标题: 请教:多个变量的比较问题 [打印本页] 作者: shiyiming 时间: 2008-11-16 10:52 标题: 请教:多个变量的比较问题 数据集A中有两组变量 q1-q10;b1-b12;都是数值型的.注意其中有好多变量有缺失值.甚至整个变量都缺失.把b1-b12的值都包含在q1-q10中的筛选出来,放到EXCEL里 ,其他的即:至少存在 一个不在Q1-Q10的放到另一个表中.谢谢作者: shiyiming 时间: 2008-11-16 13:17 标题: Re: 请教:多个变量的比较问题 I'm not sure, but something like the 2nd data step may work out.
[code:27vhwl2d]
data a;
array b[*] b1-b12;
array q[*] q1-q10;
do k=1 to 10;
do i=1 to dim(b);
b[i] = floor(ranuni(0)*5);
if b[i] = 0 then b[i]=.;
end;
do i=1 to dim(q);
q[i] = floor(ranuni(0)*5);
if q[i] = 0 then q[i]=.;
end;
output;
end;
drop k i;
format b1-b10 q1-q10 1.;
data inclusive not_inclusive;
array b[*] b1-b12;
array q[*] q1-q10;
set a;
str = peekclong(addrlong(q[1]), 8*dim(q));
count_diff = 0;
do i=1 to dim(b);
if index(str, put(b[i], rb8.))=0 then count_diff++1;
end;
if count_diff>0 then output not_inclusive; else output inclusive;
drop i str count_diff;
proc print data=inclusive;
proc print data=not_inclusive;
run;
*proc export ... ...;
[/code:27vhwl2d]
it is more efficient if you sort arrays b and q first, then compare their elements from left to right.