BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
leahcho
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Shame on you @Enio! 😉 

 

And I agree completely with @RW9 and @Enio, PROC APPEND is the way to go if you take performance into account.

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20
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;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

Enio
Fluorite | Level 6

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;

 

PeterClemmensen
Tourmaline | Level 20

Shame on you @Enio! 😉 

 

And I agree completely with @RW9 and @Enio, PROC APPEND is the way to go if you take performance into account.

leahcho
Obsidian | Level 7
Thanks guys for your help!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1399 views
  • 2 likes
  • 4 in conversation