我有一个数据集,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;
你混淆了 AND 和 OR:
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;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句