删除SAS主数据集的输出(子集)



我想从SAS的主数据集中删除子集(我正在创建if-then输出语句)。在下面的示例中,在下一步中,我想从数据集z中删除子集a b和c中的条目/行。请分享您的想法。

data a b c;
set z;
if find(scan(name,1,' '),',') and find(name,' MD ') then output a;
else if find(scan(name,1,' '),',') and not find(name,' MD ') then output b;
else if count(strip(name),' ')=2 and length(compress(scan(name,2,' '),'.'))=1 then output c;
run;

谢谢!

首先,如果这是您的实际程序,那么您应该在相同的数据步骤中简单地输出到new-z。

data a b c z_new; 
set z;
if ... then output a;
else if ... then output b;
else if ... then output c;
else output z_new;
run;

然而,如果这是人为的问题,a/b/c是在别处创建的,你有很多选择,这主要取决于数据的大小——这需要有多高效,以及其他决定什么是"高效"one_answers"可能"的细节。

最直接的是merge:

data z_new;
merge z(in=_z) a(in=_a) b(in=_b) c(in=_c);
by name;
if _z and not (_a or _b or _c);
run;

只保留在z中的记录,而不是在a, b或c中的记录。这假设name是唯一标识符-如果不是,则使用唯一标识符作为by变量。

最新更新