SAS中删除指定SAStime范围内满足Code=1条件的行的方法
SAS 实现方案
核心筛选逻辑
你需要排除的是同时满足两个条件的行:Code=1、SAStime处于0到85800的闭区间,写条件时注意逻辑运算符优先级,避免判断错误。
方法1:Data步实现
用delete语句显式删除不符合要求的行
data 输出数据集名; set 原数据集名; if Code=1 and (SAStime >= 0 and SAStime <= 85800) then delete; run;
用where语句直接筛选(大数据集效率更高)
data 输出数据集名; set 原数据集名; where not (Code=1 and SAStime between 0 and 85800); run;
方法2:PROC SQL实现
proc sql; create table 输出数据集名 as select * from 原数据集名 where not (Code=1 and SAStime between 0 and 85800); quit;
常见问题排查
如果之前的尝试未生效,大多是逻辑条件写反导致:不要误写为只保留Code=2的行,上述通用写法可以兼容后续数据集里出现其他Code值、其他时间区间的场景,不会误删符合要求的数据。
内容的提问来源于stack exchange,提问作者elemarles
相关产品推荐
相关产品推荐

