Hi,
I have datasets that have multiple lines for person IDs and not sure if I can append these datasets.
So my data contain;
Dataset1
ID A B C
1 1 2 .
1 . . 3
1 1 . .
2 1 3 1
2 . 2 1
2 . 2 .
Dataset 2
ID A B C
3 1 2 .
3 . . 3
3 1 . .
4 1 3 1
4 . 2 1
4 . 2 .
Is it possible to append dataset 1 and 2 and retain all the data in those datasets?
Thanks.
data Dataset1;
input ID$ A B C;
datalines;
1 1 2 .
1 . . 3
1 1 . .
2 1 3 1
2 . 2 1
2 . 2 .
;
data Dataset2;
input ID$ A B C;
datalines;
3 1 2 .
3 . . 3
3 1 . .
4 1 3 1
4 . 2 1
4 . 2 .
;
data want;
set Dataset1 Dataset2;
run;
Just to add, you may want to use proc append, it should be quicker than a datastep as it doesn't read the data:
http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a000070936.htm
Hi,
Combining both into a third dataset using a set statement is very common, but it is a great habit to get into using proc append as (mentioned already) this can have significant performance benefits when working with large datasets. (Many thanks to @PeterClemmensen as I shamelessly copied your code to start with!)
This example will simply append dataset2 onto dataset1:
data Dataset1;
input ID$ A B C;
datalines;
1 1 2 .
1 . . 3
1 1 . .
2 1 3 1
2 . 2 1
2 . 2 .
;
data Dataset2;
input ID$ A B C;
datalines;
3 1 2 .
3 . . 3
3 1 . .
4 1 3 1
4 . 2 1
4 . 2 .
;
proc append base=dataset1 data=dataset2; run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.