首先,oloolo楼主对类似情况有研究。
替换缺失值后,试试这个:
[code:2yofm0sa]data n (drop=_:);
array _v[5] x1-x5;
set w;by id;
_diff=constant("big");
do _i=1 to 5;
_ndiff=abs(_v[_i]-16);
if _ndiff=>_diff then continue;
_diff=_ndiff;
x6=_v[_i];
end;
run;
proc print;run;[/code:2yofm0sa]
数据的缺失值是?在上面的代码上加入一个数组,不知道这样理解对不对(缺失值存在影响结果)
[code:1zake3zp]data n (drop=_:);
array _v[5] x1-x5;
array _w[5] y1-y5;
set j;by id;
_diff=constant("big");
do _i=1 to 5;
_ndiff=abs(_v[_i]-16);
if _ndiff=>_diff then continue;
_diff=_ndiff;
x6=_v[_i];
y6=_w[_i];
end;
run;
proc print;run;[/code:1zake3zp]
data n2 (drop=_:);
array _v[5] x1-x5;
set w;by id;
_diff=constant("big");
do _i=1 to 5;
if not missing(_v(_i)) then do;
_ndiff=abs(_v[_i]-16);
if _ndiff=>_diff then continue;
_diff=_ndiff;
x6=_v[_i];
end;
end;
run;
[quote="sun59338":c43tps2u]加上一个判断- if not missing(_v(_i)) then do;.....;end;
data n2 (drop=_:);
array _v[5] x1-x5;
set w;by id;
_diff=constant("big");
do _i=1 to 5;
if not missing(_v(_i)) then do;
_ndiff=abs(_v[_i]-16);
if _ndiff=>_diff then continue;
_diff=_ndiff;
x6=_v[_i];
end;
end;
run;[/quote:c43tps2u]
<!-- s:D --><img src="{SMILIES_PATH}/icon_biggrin.gif" alt=":D" title="Very Happy" /><!-- s:D --> 谢谢,受用了~~~