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: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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