I have 3 dataset as shown:
data dataA;
input id;
datalines;
1001
1002
1003
;
run;
data dataB;
input id;
datalines;
1001
1002
1003
;
run;
data dataC;
input id;
datalines;
1001
1002
1003
;
run;
i would like to have output:
1001 dataA
1002 dataA
1003 dataA
1001 dataB
1002 dataB
1003 dataB
1001 dataC
1002 dataC
1003 dataC
I know how to combine three data sets using
data datacombine;
set dataA dataB dataC;
run;
If you have SAS 9.2 or newer then you could use the INDSNAME option http://support.sas.com/kb/34/513.html
data datacombine;
format dsname datasetname $25.;
set dataA dataB dataC indsname=dsname;
datasetname=dsname;
run;
I think this is the most standard way of doing it:
data datacombine;
set dataA(in=A) dataB(in=B) dataC(in=C);
if A then origin = "dataA";
else if B then origin = "dataB";
else if C then origin = "dataC";
run;
The in= dataset option sets a flag if the row originated from the corresponding input dataset.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With