按 ID 和日期填充 SAS 中的字段

Populate fields in SAS by ID and Date

我的数据集如下所示:

AsAtDate  ReleaseDate ID Var1 Var2 ... Var5
200701     200601      1   x    .    
200702     200601      1   .    a
200703     200601      1   .    .
200701     200702      2   .    b 
200702     200702      2   y    b
200703     200702      2   y    .
200702     200501      3   z    .
200703     200501      3   .    .

我希望我的结果如下所示:

AsAtDate  ReleaseDate ID Var1 Var2 ... Var5
200701     200601      1   x    a    
200702     200601      1   x    a
200703     200601      1   x    a
200701     200702      2   .    . 
200702     200702      2   y    b
200703     200702      2   y    b
200702     200501      3   z    .
200703     200501      3   z    .

如何让我的数据考虑 ReleaseDate,如果 ReleaseDate 早于 AsAtDate,则按 ID 填充字段。

我试过下面的代码,还有比这更简化的代码吗?

proc sql;
create table want as
select *, max(Var1) as _Var1
from have
group by ID
order by ID, AsAtdate;
quit;

data want1;
set want;
by id;
if ReleaseDate > AsAtDate then _Var1='';
run; 

基于您的解决方案,我们可以添加 CASE 语句以根据需要有条件地填写数据。

proc sql;
create table want as
select *, 
       case when ReleaseDate>AsAtDate then " " 
       else max(Var1) 
       end as _Var1
from have
group by ID
order by ID, AsAtdate;
quit;