DATA Step, Macro, Functions and more

Combine two data sets using SET statements

Reply
Contributor
Posts: 27

Combine two data sets using SET statements

Given the SAS data sets:
WORK.FIRST WORK.SECOND
Common X Common Y
------ -- ------ --
A 10 A 1
A 13 A 3
A 14 B 4
B 9 B 2
The following SAS program is submitted:
data WORK.COMBINE;
set WORK.FIRST;
set WORK.SECOND;
run;
What data values are stored in data
set WORK.COMBINE?
A.
Common X Y
------ -- --
A 10 1
A 13 3
B 14 4
B 9 2
B.
Common X Y
------ -- --
A 10 1
A 13 3
A 14 3
B 9 4
B 9 2
C.
Common X Y
------ -- --
A 10 1
A 13 3
A 14 .
B 9 4
B . 2
D.
Common X Y
------ -- --
A 10 1
A 13 1
A 14 1
A 10 3
A 13 3
A 14 3
B 9 4
B 9 2
AnswerSmiley SadA)

I don't understand that the third row starts with "B" instead of "A" in answer (A). Why? Can someone help? Thanks. Message was edited by: richard_hu2003
Frequent Contributor
Posts: 81

Re: Combine two data sets using SET statements

When multiple SET statements are used, number of observations in the new data set is the number of observations in the smallest original data set. If the data sets contain common variables, the values that are read in from the last data set replace those read in from earlier ones.

During the third iteration, when the record is read using SET statement from FIRST dataset, the value of 'Common' in PDV is A. However, when the second SET statement is executed, the value of 'Common' (A) in PDV is replaced by 'B' from SECOND dataset.
Contributor
Posts: 27

Re: Combine two data sets using SET statements

Very detailed explanation. Thanks, Nick!
Ask a Question
Discussion stats
  • 2 replies
  • 420 views
  • 0 likes
  • 2 in conversation