标题: 请教:如何删除SAS数据集的空记录? [打印本页] 作者: shiyiming 时间: 2009-7-27 09:45 标题: 请教:如何删除SAS数据集的空记录? 如题,整理数据集,如何删除其中的空记录?
谢谢!作者: shiyiming 时间: 2009-7-27 12:28 标题: Re: 请教:如何删除SAS数据集的空记录? if var = . then delete ?
LZ想问的是什么呢作者: shiyiming 时间: 2009-7-27 14:41 标题: Re: 请教:如何删除SAS数据集的空记录? to karen1234
删除数据集行操作,“if var = . then delete ”应该是删除列作者: shiyiming 时间: 2009-7-27 21:42 标题: Re: 请教:如何删除SAS数据集的空记录? [code:3un9xmkt]
data test2;
set test;
where var ge 0;
run;
[/code:3un9xmkt]
只选择非空的观测保存,不知道这样服不符合你的要求作者: shiyiming 时间: 2009-7-28 15:11 标题: Re: 请教:如何删除SAS数据集的空记录? 曾经见过一外国人写的Macro,是用来删除空记录的,当时没看懂,存来存去后来找不到了.
我现在用的笨办法是用函数NMISS()
if nmiss(of x1-x10)=10 then delete;作者: shiyiming 时间: 2009-7-30 09:28 标题: Re: 请教:如何删除SAS数据集的空记录? to teahon
如何从metadata读表信息不会写,期待高手指点。作者: shiyiming 时间: 2009-8-4 13:56 标题: Re: 请教:如何删除SAS数据集的空记录? 试试看这个...
[code:f6lsngbu]%macro dltblk(inds=,outds=);
proc contents data=&inds out=out(keep=name type) noprint;
run;
data _null_;
set out end=eof;
call symput ('var'||strip(put(_n_,8.)),name);
call symput ('type'||strip(put(_n_,8.)),type);
if eof then do;
call symput ('i',_n_);
run;
%put _user_;
data &outds(drop=count);
set &inds; count=0;
%do j=1 %to &i;
if &&type&j=1 then do;
if &&var&j=. then count+1;
end;
if &&type&j=2 then do;
if &&var&j="" then count+1;
end;
%end;
if count=&i then delete;
run;
%mend dltblk;
[/code:f6lsngbu]作者: shiyiming 时间: 2009-8-4 17:18 标题: Re: 请教:如何删除SAS数据集的空记录? 凑热闹,就是不知道变量多的时候函数的效率如何.
[code:15shshhg]data temp(drop=i);
set sashelp.class end=last;
output;
if last then do;
call missing(of _all_);
do i=1 to 10;
output;
end;
end;
run;
data temp2;
set temp;
if n(of _numeric_)=0 and cats(of _character_)=' ' then delete;
run;[/code:15shshhg]作者: shiyiming 时间: 2009-8-5 10:58 标题: Re: 请教:如何删除SAS数据集的空记录? 楼主是我同事,这问题引来这么多高手回答。
首先这种情况很少发生,一般数据中都有关键词,只需要判断关键词是否为非空就可以。
DATA A;
INPUT A B C$;
CARDS;
1 3 5
. . C
3 . .
. . .
;
RUN;
DATA M;
SET A;
_DID=OPEN("A");
_DNVAR=ATTRN(_DID,"NVARS");
DROP _:;
IF CMISS(OF _ALL_) NE _DNVAR;
RUN;作者: shiyiming 时间: 2009-8-5 16:47 标题: Re: 请教:如何删除SAS数据集的空记录? 谢谢4772814,还真没留意到这个9.2的新函数.作者: shiyiming 时间: 2009-8-6 15:54 标题: Re: 请教:如何删除SAS数据集的空记录? to 4772814