Table of Contents
The SET statement in SAS allows for the merging of multiple datasets into one, implementing the concept of “Single Assignment.” This concept ensures that each observation in the output dataset is assigned only once, even if it appears in multiple input datasets. By using the SET statement with multiple datasets, SAS efficiently combines data and avoids duplication, improving data accuracy and reducing processing time. This feature is particularly useful when working with large datasets and performing complex data manipulations. Overall, utilizing the SET statement with multiple datasets in SAS is a powerful tool for implementing the programming concept of “Single Assignment” and improving data management in SAS.
SAS: Use SET Statement with Multiple Datasets
You can use the following basic syntax to include multiple datasets in the set statement in SAS:
data new_data;
set data1 data2 data3;
run;
The following example shows how to use this syntax in practice.
Example: Use SET Statement with Multiple Datasets in SAS
Suppose we have the following dataset in SAS that shows the points scored by various basketball players on a team called A:
/*create first dataset*/
data data1;
input team $ points;
datalines;
A 12
A 15
A 16
A 21
A 22
;
run;
/*view dataset*/
proc printdata=data1;

And suppose we have another dataset that shows the points scored by various basketball players on a team called B:
/*create second dataset*/
data data2;
input team $ points;
datalines;
B 16
B 22
B 25
B 29
B 30
;
run;
/*view dataset*/
proc printdata=data2; 
We can use the set statement with multiple datasets to combine these two datasets into one:
/*create new dataset that combines two datasets*/
data data3;
set data1 data2;
run;
/*view new dataset*/
proc printdata=data3; 
The result is a third dataset called data3 that combines the rows from data1 and data2.
Note: Even if the two datasets didn’t share the same column names, the set statement would still combine the datasets into one and simply leave empty spaces in the cells where the columns don’t match.
The following tutorials explain how to perform other common tasks in SAS:
Cite this article
stats writer (2024). How can I use the SET statement with multiple datasets in SAS to implement the SAS programming concept of “Single Assignment (SAS)”?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-use-the-set-statement-with-multiple-datasets-in-sas-to-implement-the-sas-programming-concept-of-single-assignment-sas/
stats writer. "How can I use the SET statement with multiple datasets in SAS to implement the SAS programming concept of “Single Assignment (SAS)”?." PSYCHOLOGICAL SCALES, 26 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-i-use-the-set-statement-with-multiple-datasets-in-sas-to-implement-the-sas-programming-concept-of-single-assignment-sas/.
stats writer. "How can I use the SET statement with multiple datasets in SAS to implement the SAS programming concept of “Single Assignment (SAS)”?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-use-the-set-statement-with-multiple-datasets-in-sas-to-implement-the-sas-programming-concept-of-single-assignment-sas/.
stats writer (2024) 'How can I use the SET statement with multiple datasets in SAS to implement the SAS programming concept of “Single Assignment (SAS)”?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-use-the-set-statement-with-multiple-datasets-in-sas-to-implement-the-sas-programming-concept-of-single-assignment-sas/.
[1] stats writer, "How can I use the SET statement with multiple datasets in SAS to implement the SAS programming concept of “Single Assignment (SAS)”?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.
stats writer. How can I use the SET statement with multiple datasets in SAS to implement the SAS programming concept of “Single Assignment (SAS)”?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
