DATA Step, Macro, Functions and more

Append datasets

Accepted Solution Solved
Reply
Contributor
Posts: 29
Accepted Solution

Append datasets

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.


Accepted Solutions
Solution
‎12-08-2017 04:29 PM
PROC Star
Posts: 1,190

Re: Append datasets

Shame on you @Enio! Smiley Wink 

 

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


All Replies
PROC Star
Posts: 1,190

Re: Append datasets

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;
Super User
Super User
Posts: 9,193

Re: Append datasets

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

Occasional Contributor
Posts: 10

Re: Append datasets

[ Edited ]

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 @draycut 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;

 

Solution
‎12-08-2017 04:29 PM
PROC Star
Posts: 1,190

Re: Append datasets

Shame on you @Enio! Smiley Wink 

 

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

Contributor
Posts: 29

Re: Append datasets

Thanks guys for your help!
☑ This topic is solved.

Need further help from the community? Please ask a new question.

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