Published on :
ETL CREATION_INTERNE

Examples: Combining data one-to-one

This code is also available in: Deutsch Español Français
Awaiting validation
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!
1DATA animal;
2 INPUT common $ animal $;
3 DATALINES;
4a Ant
5b Bird
6c Cat
7d Dog
8e Eagle
9f Frog
10;
11RUN;
12 
13DATA plantG;
14 INPUT common $ plant $;
15 DATALINES;
16a Apple
17b Banana
18c Coconut
19d Dewberry
20e Eggplant
21g Fig
22;
23RUN;
24 
25DATA combine;
26 SET animal;
27 SET plantG;
28RUN;
29 
30PROC PRINT DATA=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.