Published on :
ETL CREATION_INTERNE

Examples: Combining data one-to-one

This code is also available in: Deutsch Français
Awaiting validation
The SET statement is used to combine SAS© datasets observation by observation, without matching the values of a common variable. The order of SET statements is crucial: shared variable values from the last specified dataset replace those from previous datasets for the same observation. The process reads the first observation from the first dataset, then the first from the second, and so on. The resulting output dataset contains all variables from all input datasets. The DATA step stops selecting observations once the dataset with the fewest observations is fully read. To combine datasets with an unequal number of observations by directly accessing and matching observations by a common variable, the POINT= option can be used.
Data Analysis

Type : CREATION_INTERNE


The examples use generated data (datalines) to create the 'animal' and 'plantG' datasets before their combination.

1 Code Block
DATA STEP Data
Explanation :
This SAS code creates two temporary datasets, 'animal' and 'plantG', with internal data. Then, it combines these two datasets using two consecutive SET statements into a new dataset named 'combine'. Each observation from the 'animal' dataset is read, then each corresponding observation (in read order) from the 'plantG' dataset is read. In the case of a common variable ('common'), the value from the last dataset (here 'plantG') overwrites that from the previous one. Proc PRINT displays the content of the 'combine' dataset.
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.
Copyright Info : Copyright © SAS Institute Inc. All Rights Reserved