How to Concatenate Datasets in SAS (With Example)

The CONCATENATE statement in SAS is used to combine two or more datasets together into a single dataset. This statement should be used in the DATA step of your program. To use this statement, the datasets must have the same columns and the same order of columns. An example of how to use the CONCATENATE statement is to combine two datasets, dataset1 and dataset2, into a single dataset, dataset3, using the following syntax: DATA dataset3; SET dataset1 dataset2; RUN;


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 print data=data1;
proc print data=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 print data=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.

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

x