This feature combines observations from two or more datasets by associating them positionally. The SET statement reads one observation from each listed dataset at each DATA step iteration. Variables common to the datasets are overwritten by the values of the dataset specified last in the SET statement. The process stops once the dataset containing the fewest observations has been fully read, which determines the final number of observations in the resulting dataset. This method does not rely on a key variable for matching and can produce unexpected results if datasets have common variables with unsynchronized values.
Data Analysis
Type : CREATION_INTERNE
Examples use generated data (datalines) or SASHELP. The 'animal' and 'plantG' datasets are created internally for illustration.
1 Code Block
DATA STEP / PROC PRINT Data
Explanation : This SAS code creates two datasets, 'animal' and 'plantG', then combines them using two consecutive SET statements. The DATA step reads one observation from 'animal' then one observation from 'plantG' for each iteration. The values of the 'common' variable from the 'plantG' dataset (specified last) overwrite those from the 'animal' dataset. The resulting 'combine' dataset will have a number of observations equal to that of the smallest input dataset. The PROC PRINT output shows the combined dataset, illustrating how 'common' values from 'plantG' were retained, even when diverging at the sixth observation (where 'animal' had 'f' and 'plantG' had 'g', 'g' from 'plantG' is kept).
Copied!
data animal;
input common $ animal $;
datalines;
a Ant
b Bird
c Cat
d Dog
e Eagle
f Frog
;
run;
data plantG;
input common $ plant $;
datalines;
a Apple
b Banana
c Coconut
d Dewberry
e Eggplant
g Fig
;
run;
data combine;
set animal;
set plantG;
run;
proc print data=combine; run;
1
DATA animal;
2
INPUT common $ animal $;
3
DATALINES;
4
a Ant
5
b Bird
6
c Cat
7
d Dog
8
e Eagle
9
f Frog
10
;
11
RUN;
12
13
DATA plantG;
14
INPUT common $ plant $;
15
DATALINES;
16
a Apple
17
b Banana
18
c Coconut
19
d Dewberry
20
e Eggplant
21
g Fig
22
;
23
RUN;
24
25
DATA combine;
26
SET animal;
27
SET plantG;
28
RUN;
29
30
PROC PRINTDATA=combine; RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.