Hello
I want to stack multiple data sets using SET statement.
The data sets are: t2001,t2004,t2005 (Please note that last 4 digits are YYMM form).
I want to create a column with information from which data set the observation came from.
If observation came from data set t2001 then period=2001
If observation came from data set t2004 then period=2004
If observation came from data set t2005 then period=2005
What is the way to do it please?
Data t2001;
input ID y
cards
1 10
2 20
;
run;
Data t2004;
input ID y
cards
1 10
3 40
;
run;
Data t2005;
input ID y
cards
1 15
2 25
3 50
;
run;
Data t_All;
SET t2001 t2004 t2005;
IF observation from data set t2001 then period=2001;
IF observation from data set t2004 then period=2004;
IF observation from data set t2005 then period=2005;
Run;
Hi @Ronein Good afternoon, What you need is to use INDSNAME= option
Data t2001;
input ID y;
cards;
1 10
2 20
;
run;
Data t2004;
input ID y;
cards;
1 10
3 40
;
run;
Data t2005;
input ID y;
cards;
1 15
2 25
3 50
;
run;
Data t_All;
SET t2001 t2004 t2005 indsname=t;
period=compress(t,,'kd');
Run;
data t_all;
set t2001 (in=in1) t2004 (in=in2) t2005 (in=in3);
if in1 then period = 2001;
else if in2 then period = 2004;
else if in3 then period = 2005;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.