17.6 C
London
Tuesday, July 22, 2025
HomeSASData Munging in SASHow to Concatenate Datasets in SAS (With Example)

How to Concatenate Datasets in SAS (With Example)

Related stories

Learn About Opening an Automobile Repair Shop in India

Starting a car repair shop is quite a good...

Unlocking the Power: Embracing the Benefits of Tax-Free Investing

  Unlocking the Power: Embracing the Benefits of Tax-Free Investing For...

Income Splitting in Canada for 2023

  Income Splitting in Canada for 2023 The federal government’s expanded...

Can I Deduct Home Office Expenses on my Tax Return 2023?

Can I Deduct Home Office Expenses on my Tax...

Canadian Tax – Personal Tax Deadline 2022

  Canadian Tax – Personal Tax Deadline 2022 Resources and Tools...

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.

Additional Resources

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

How to Normalize Data in SAS
How to Remove Duplicates in SAS
How to Concatenate Strings in SAS
How to Replace Missing Values with Zero in SAS

Subscribe

- Never miss a story with notifications

- Gain full access to our premium content

- Browse free from up to 5 devices at once

Latest stories