是否可以在新计算的变量上过滤数据步骤?

时间:2017-05-24 10:27:56

标签: sas datastep

在基本数据步骤中,我正在创建一个新变量,我需要根据这个新变量过滤数据集。

data want;
    set have;

    newVariable = 'aaa';
    *lots of computations that change newVariable ;
    *if xxx then newVariable = 'bbb';
    *if yyy AND not zzz then newVariable = 'ccc';
    *etc.;

    where newVariable ne 'aaa';
run;
  

错误:变量newVariable不在文件WORK.have。

我通常分两步完成,但我想知道是否有更好的方法。

(当然你总是可以根据where statement中的变量来编写一个复杂的WORK.have。但是在这种情况下,newVariable的计算过于复杂,而且效率更高第二个data step

中的过滤器

我找不到任何关于此的信息,如果答案在文档中并且我没有找到,我为这个愚蠢的问题道歉。如果需要,我会删除这个问题。

谢谢!

1 个答案:

答案 0 :(得分:1)

使用子集if语句:

if newVariable ne 'aaa';

通常,if <condition>;相当于if not(<condition>) then delete;delete语句告诉SAS放弃数据步骤的这个迭代,然后返回到下一次迭代的开始。除非您在子集化output语句之前使用了明确的if语句,否则将阻止输出行。

相关问题