Sas 在给定特定条件下添加行
我有一个3列的数据库。ID、日期和金额。它是按ID和日期订购的。我所要做的就是在每个ID最近一次出现后添加一行,该ID具有相同的ID,日期=日期+1个月,金额=0 作为说明,我想从以下几点开始:Sas 在给定特定条件下添加行,sas,Sas,我有一个3列的数据库。ID、日期和金额。它是按ID和日期订购的。我所要做的就是在每个ID最近一次出现后添加一行,该ID具有相同的ID,日期=日期+1个月,金额=0 作为说明,我想从以下几点开始: id | Date |amount | A | 01JAN| 1 | A | 01FEB| 1 | B | 01FEB| 0 | B | 01MAR| 1 | 为此: id | Date
id | Date |amount |
A | 01JAN| 1 |
A | 01FEB| 1 |
B | 01FEB| 0 |
B | 01MAR| 1 |
为此:
id | Date |amount |
A | 01JAN| 1 |
A | 01FEB| 1 |
A | 01MAR| 0 | <- ADD THIS ROW
B | 01FEB| 0 |
B | 01MAR| 1 |
B | 01APR| 0 |<- ADD THIS ROW
id |日期|金额|
A | 1月1日| 1|
A | 2月1日| 1日|
A | 01MAR | 0 |假设日期变量中包含实际日期值,则只需在每组的最后一次观察中输出两次
data want;
set have;
by id;
output;
if last.id then do;
date=intnx('month',date,1,'b');
amount=0;
output;
end;
run;
假设DATE变量中有实际的日期值,您只需要在每组的最后一次观察中输出两次
data want;
set have;
by id;
output;
if last.id then do;
date=intnx('month',date,1,'b');
amount=0;
output;
end;
run;