Sas 如何使用AND和OR语句进行过滤?

Sas 如何使用AND和OR语句进行过滤?,sas,Sas,我有一个数据集,df,看起来像这样: ZIP TEENS ADULTS SENIORS TOTAL 054216 . 2000 . 2000 02216 45 105 10 160 01720 0 256 0 256 02113 . 4122 918 5040 02144 782

我有一个数据集,
df
,看起来像这样:

ZIP    TEENS     ADULTS     SENIORS   TOTAL
054216 .         2000       .         2000
02216  45        105        10        160
01720  0         256        0         256
02113  .         4122       918       5040
02144  782       20         0         1002
我想排除所有成人的邮政编码。此外,我只想保留成人人口超过50%的行。下面列出的代码保留第1行和第3行,即使这些社区中没有青少年或老年人。任何关于它的错误的提示都将不胜感激

data adult_zips;
    set df;
    where ((adults/total) > 0.50) and
        ((teens is not missing) or (teens ne 0)) and 
        ((seniors is not missing) or (seniors ne 0));
run;

您困惑了,或者:

data adult_zips;
    set df;
    where adults / total > 0.50 
      and 
      (
        (teens is not missing and teens ne 0)
        or
        (seniors is not missing and seniors ne 0)
      );
run;
或更简单:

data adult_zips;
    set df;
    where adults / total > 0.50 
      and (teens > 0 or seniors > 0);
run;
甚至:

data adult_zips;
    set df;
    where adults / total > 0.50 
      and adults ne total;
run;

您困惑了,或者:

data adult_zips;
    set df;
    where adults / total > 0.50 
      and 
      (
        (teens is not missing and teens ne 0)
        or
        (seniors is not missing and seniors ne 0)
      );
run;
或更简单:

data adult_zips;
    set df;
    where adults / total > 0.50 
      and (teens > 0 or seniors > 0);
run;
甚至:

data adult_zips;
    set df;
    where adults / total > 0.50 
      and adults ne total;
run;
运行

这是最简单的解决方案

运行


这是最简单的解决方案。

附带说明:我希望此数据集不是一个表。一个表不应该冗余地包含其他列的总和。一个表不应该冗余地包含其他列的总和。我们应该看到这一点。谢谢分享其他的解决方案。我应该看到这一点。感谢分享其他解决方案。