You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在SAS中标识同一ID下datevent为空与非空的行

解决方法

要精准标记同一ID下既存在datevent为空、又存在datevent非空的行,你需要修改子查询的逻辑,从单纯判断ID重复,改为判断ID同时包含空和非空的datevent记录。

修正后的PROC SQL代码

proc sql;
create table want as
select *, 
    case 
        when ID in (
            select distinct ID from HAVE where datevent is missing
            intersect
            select distinct ID from HAVE where datevent is not missing
        ) then 1 
        else 0 
    end as IDFlag
from HAVE;
quit;

代码说明

  • 子查询通过intersect(交集)操作,筛选出**同时存在缺失datevent和非缺失datevent**的ID集合
  • 外层case when判断当前行的ID是否在这个集合里,是则标记为1,否则为0
  • 这样就能精准定位到那些ID下两种datevent状态都存在的所有行

内容的提问来源于stack exchange,提问作者Sai Paritala

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 07:35:11