我使用以下代码为每个 ID 分配年份 2017,2018,2019,2020:
proc sort data=Have;
by ID;
run;
data Have2;
set Have(keep=id);
by id ;
if first.id then do Vintage= 2017 to 2020;
output;
end;
run;
proc sort data=have2;
by id;
run;
data have3 ;
merge have2 have;
by id;
run;
这样数据集看起来像这样:
data have3;
input ID Vintage;
datalines;
1 2017
1 2018
1 2019
1 2020
2 2017
2 2018
2 2019
2 2020
3 2017
3 2018
3 2019
3 2020
4 2017
4 2018
4 2019
4 2020
;
run;
现在的问题是我正在处理一个看起来像这样的数据集
data newdata;
input ID Type;
datalines;
1 A
1 A
1 A
1 A
1 L
1 L
1 L
1 L
2 A
2 A
2 A
2 A
2 L
2 L
2 L
2 L
;
run;
现在Vintage附加在2017,2018,2019,2020,2020,2020,2020
有没有一种方法可以通过 ID 和类型附加到年份,使上面的数据看起来像这样
data want;
input ID Type Vintage;
datalines;
1 A 2017
1 A 2018
1 A 2019
1 A 2020
1 L 2017
1 L 2018
1 L 2019
1 L 2020
2 A 2017
2 A 2018
2 A 2019
2 A 2020
2 L 2017
2 L 2018
2 L 2019
2 L 2020
;
run;
TIA