-3

我的数据集如下所示:

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 填充字段。

4

2 回答 2

1

在您的解决方案的基础上,我们可以添加 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;
于 2018-09-21T15:10:28.570 回答
0

我尝试了以下代码,有没有比这更简化的代码?

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; 
于 2018-09-21T01:47:35.707 回答