在优化代码期间,我遇到了一些问题。我需要使用 ONE 仅数据步骤
data step1;
merge table1(in=in1) table2(in=in2 rename=(field2=field22));
by field1;
If (in1=1 and in2=1) then output;run;
data step2;
set step1;
If field1=field22 then mark=1 output;run;
proc sql;
create table step3 as select sum(mark1) from step2 group by field1;quit;run;
有可能吗?谢谢!
答案 0 :(得分:0)
因此,您希望按FIELD1进行分组,并计算TABLE2中有多少记录具有FIELD1 = FIELD2,但仅当FIELD1也出现在TABLE1中时。
data want ;
do until (last.field1);
merge table1 (in=in1) table2(in=in2 where=(field1=field2));
by field1;
count=sum(count,in1 and in2);
end;
keep field1 count;
run;
如果要查找FIELD11 ne FIELD22中存在任何值的所有情况,则可以添加双DOW循环。
data want ;
do until (last.field1);
merge table1 (in=in1) table2(in=in2) ;
by field1;
if in1 and in2 and (field11 ne field22) then missmatch=1;
end;
do until (last.field1);
merge table1 (in=in1) table2(in=in2) ;
by field1;
if missmatch then output;
end;
run;