Published on :
ETL INTERNAL_CREATION

Example of table merging by identifier

This code is also available in: Deutsch Español Français
Awaiting validation
This program creates two temporary SAS© tables (sample1 and sample2) containing simulated data (student grades). It displays this data, then merges the two tables on the common column 'sid' to create a consolidated table named 'MERGED', whose content is then displayed.
Data Analysis

Type : INTERNAL_CREATION


Data is generated directly in the source code via the DATALINES statement.

1 Code Block
DATA STEP Data
Explanation :
Creation of dataset 'sample1' containing an identifier (sid) and a mark.
Copied!
1DATA sample1;
2 INPUT sid mark;
3 DATALINES;
41 100
52 90
63 30
74 50
85 60
9;
2 Code Block
DATA STEP Data
Explanation :
Creation of dataset 'sample2' containing an identifier (sid) and two other marks (mark1, mark2).
Copied!
1DATA sample2;
2 INPUT sid mark1 mark2;
3 DATALINES;
41 90 80
52 80 76
63 75 23
74 62 42
85 71 43
9;
3 Code Block
PROC PRINT
Explanation :
Visualization of the two source datasets.
Copied!
1PROC PRINT DATA=sample1;
2PROC PRINT DATA=sample2;
4 Code Block
DATA STEP Data
Explanation :
Merging tables 'sample1' and 'sample2' by aligning observations on the key variable 'sid'. The result is stored in the 'MERGED' table.
Copied!
1DATA MERGED;
2 MERGE sample1 sample2;
3 BY sid;
5 Code Block
PROC PRINT
Explanation :
Visualization of the merge result and script termination.
Copied!
1PROC PRINT DATA=MERGED;
2 
3RUN;
4QUIT;
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.