我想从数据集中删除所有空白观察值。
我只知道如何摆脱一个变量的空白:
data a;
set data(where=(var1 ne .)) ;
run;
在这里,我设置了一个新的数据集,而var1中没有空格。
但是,当我想摆脱整个数据集中的所有空白时,该怎么办?
预先感谢您的回答。
最佳答案
如果您试图摆脱缺少所有变量的行,这很容易:
/* Create an example with some or all columns missing */
data have;
set sashelp.class;
if _N_ in (2,5,8,13) then do;
call missing(of _numeric_);
end;
if _N_ in (5,6,8,12) then do;
call missing(of _character_);
end;
run;
/* This is the answer */
data want;
set have;
if compress(cats(of _all_),'.')=' ' then delete;
run;
除了压缩以外,您还可以事先使用
OPTIONS MISSING=' ';
。如果要删除所有缺少值的所有行,则可以使用NMISS/CMISS函数。
data want;
set have;
if nmiss(of _numeric_) > 0 then delete;
run;
或者
data want;
set have;
if nmiss(of _numeric_) + cmiss(of _character_) > 0 then delete;
run;
适用于所有字符+数字变量。
关于sas - 如何在SAS中删除数据集中的空白观测值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17291756/