与 if 语句数据步骤合并

  • 本文关键字:合并 数据 if 语句 sas
  • 更新时间 :
  • 英文 :


在优化代码期间,我遇到了一些问题。我只需要使用一个数据步骤

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;

有可能做到吗?谢谢!

因此,您希望按字段 1 分组并计算 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;

最新更新