I know there's a way to do this but I cannot remember what the option is called and am also having trouble looking it up.
I essentially want to stack multiple datasets and have a column created with their names in it so I can keep track of which data belongs to which dataset.
data have1;
var1 = 'A'; var2= 'BC'; var3= 1;
data have2;
var1 = 'D'; var2= 'EF'; var3= 2;
data have;
set have1 have2;
run;
data want;
input dsn $ var1 $ var2 $ var3 @@;
cards;
have1 A BC 1
have2 D EF 2
;
run;
Use the INDSNAME (Input DataSet Name) option
data have; length source src $40.; set have1 have2 indsname = source; src=source; run;
Use the INDSNAME (Input DataSet Name) option
data have; length source src $40.; set have1 have2 indsname = source; src=source; run;
Check out Where did it come from? Adding the source of each observation to a SAS data set by Rick Wicklin.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.