How can I concatenate datasets in SAS, and what is an example of this process? 2

How can I concatenate datasets in SAS, and what is an example of this process?

Concatenating datasets in SAS is a process of combining multiple datasets into one larger dataset. This can be useful when working with large datasets that are split into smaller parts or when merging datasets with common variables. The CONCATENATE statement in SAS allows users to easily combine datasets by stacking them on top of each other, creating a single dataset with all the variables and observations from the original datasets. For example, if we have two datasets, one with sales data for the first quarter and another with sales data for the second quarter, we can use the CONCATENATE statement to combine them into one dataset with sales data for the entire year. This process can save time and effort when working with multiple datasets in SAS.

Concatenate Datasets in SAS (With Example)


You can use the following basic syntax to concatenate datasets in SAS:

/*concatenate two datasets into one*/
data data3;
	set data1 data2;
run;

The following example shows how to use this syntax in practice.

Example: Concatenate Datasets in SAS

Suppose we have the following two datasets in SAS:

/*create first dataset*/
data data1;
    input firstName $ lastName $ points;
    datalines;
Austin Smith 15
Brad Stevens 31
Chad Miller 22
;
run;

/*create second dataset*/
data data2;
    input firstName $ lastName $ points;
    datalines;
Dave Michaelson 19
Eric Schmidt 29
Frank Wright 20
Greg Gunner 40
Harold Anderson 35
;
run;

/*view datasets*/
proc printdata=data1;
proc printdata=data2;

SAS concatenate datasets

We can use the following code to concatenate these two datasets into one dataset:

/*concatenate two datasets into one*/
data data3;
	set data1 data2;
run;

/*view new dataset*/
proc printdata=data3;

The resulting dataset contains all of the observations from the first two datasets.

Note: In this example we concatenated only two datasets into one. However, we can use similar syntax to concatenate as many datasets as we’d like. The only requirement is that each dataset contains the same variable names.

Additional Resources

The following tutorials explain how to perform other common tasks in SAS:

Cite this article

stats writer (2024). How can I concatenate datasets in SAS, and what is an example of this process?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-concatenate-datasets-in-sas-and-what-is-an-example-of-this-process/

stats writer. "How can I concatenate datasets in SAS, and what is an example of this process?." PSYCHOLOGICAL SCALES, 1 Jul. 2024, https://scales.arabpsychology.com/stats/how-can-i-concatenate-datasets-in-sas-and-what-is-an-example-of-this-process/.

stats writer. "How can I concatenate datasets in SAS, and what is an example of this process?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-concatenate-datasets-in-sas-and-what-is-an-example-of-this-process/.

stats writer (2024) 'How can I concatenate datasets in SAS, and what is an example of this process?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-concatenate-datasets-in-sas-and-what-is-an-example-of-this-process/.

[1] stats writer, "How can I concatenate datasets in SAS, and what is an example of this process?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, July, 2024.

stats writer. How can I concatenate datasets in SAS, and what is an example of this process?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.

Download Post (.PDF)
Slide Up
x
PDF
Scroll to Top