data b;
infile datalines;
input x y3 y4;
datalines;
1 1 2
3 3 4
;
run;
data c;
merge a(in=ina) b(in=inb);
by x;
run;[/code:1mr75ar9]作者: shiyiming 时间: 2008-3-5 15:05 标题: Re: 求助:如何高效的填补空缺值 data c;
merge a(in=ina) b(in=inb);
array a(*) y1 y2;
array b(*) y3 y4;
by x;
do i=1 to 2;if ^ina then a(i)=0;end;
do j=1 to 2;if ^inb then b(j)=0;end;
drop i j;
run;
data d;
set c;
z=y1+y2+y3+y4;
run;[/code:2edmqcd3]
[quote:2edmqcd3]848 data d;
849 set c;
850 z=y1+y2+y3+y4;
851 run;
NOTE: Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line):(Column).
1 at 850:5 2 at 850:8
NOTE: There were 4 observations read from the data set WORK.C.
NOTE: The data set WORK.D has 4 observations and 6 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds[/quote:2edmqcd3]
你会发现z的值好多都是缺失,证明option missing只是把显示改成了0,没有真正把值改成0。 <!-- s:) --><img src="{SMILIES_PATH}/icon_smile.gif" alt=":)" title="Smile" /><!-- s:) -->作者: shiyiming 时间: 2008-3-5 15:54 标题: Re: 求助:如何高效的填补空缺值 <!-- s:shock: --><img src="{SMILIES_PATH}/icon_eek.gif" alt=":shock:" title="Shocked" /><!-- s:shock: --> 对的,写个判断是0 or 缺失的赋不同的值就可以知道了。翻了下书确实是这样....
还是期待更好的方法。 <!-- s:D --><img src="{SMILIES_PATH}/icon_biggrin.gif" alt=":D" title="Very Happy" /><!-- s:D -->作者: shiyiming 时间: 2008-3-6 15:04 标题: Re: 求助:如何高效的填补空缺值 Fancy的options我从来都不知道。
我的办法是要有两个缺失值的数据集。目标数据集merge后再与缺失值的数据集merge两下。注意排序。
[code:11t4iodf]data left;
input id a$ b ;
cards;
1 A 2
4 X 3
;
run;
data defaultL;
A='@';
b=0;
Lflg=1;
run;
data right;
input id c d;
cards;
1 4 7
2 6 9
;
run;
data defaultR;
C=0;
d=99;
Rflg=1;
run;
data big;
merge left(in=inL) right(in=inR);
by id;
Lflg=not inL;
Rflg=not InR;
run;
proc sort data=big;
by Lflg;
run;
data final;
merge big defaultL;
by Lflg;
run;
proc sort data=final;
by Rflg;
run;
data final(drop=lflg rflg);
merge final defaultR;
by Rflg;
run;[/code:11t4iodf]作者: shiyiming 时间: 2008-3-6 15:37 标题: to ahuige 为解决大量(几百个)变量的补缺,这的确是个好办法。需要补缺的越多,这段程序的优势就越明显。谢谢你!
[code:2ifhcb2d]proc iml;
use c;
read all into x[colname=cols];
x[LOC(x<0)]=0;
create d from x[colname=cols];
append from x;
quit;[/code:2ifhcb2d]作者: shiyiming 时间: 2008-4-4 01:23 标题: Re: 求助:如何高效的填补空缺值 The following program recode 999 and 888 to '.' (for numerical variables) or ' ' (for characteristic variables). By revising it , you can recode missing to any number you want or recode any number to missing value.
[code:1cju2kty]%macro recodemiss(dataset);
data &dataset;
set &dataset;
array num[*] _numeric_;
array char[*] _character_;
do i=1 to dim(num);
if num[i] = 999 or num[i]=888 then num[i]= .;
end;
do j=1 to dim(char);
if char[j]=999 or char[j]=888 then char[j]= ' ';
end;
run;