4.2 C
London
Friday, December 20, 2024
HomeSASDescriptive Statistics in SASHow to Use Proc Append in SAS (With Examples)

How to Use Proc Append in SAS (With Examples)

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 PROC APPEND in SAS to append the values of one dataset to the end of another dataset.

This procedure uses the following basic syntax:

proc append
    base=data1
    data=data2;
run;

Note that this procedure doesn’t create a new dataset. Rather, it automatically appends the values in data2 to the end of data1.

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

Example: Using Proc Append in SAS

Suppose we have the following two datasets in SAS:

/*create datasets*/
data data1;
    input team $ points rebounds;
    datalines;
A 25 10
B 18 4
C 18 7
D 24 12
E 27 11
;
run;

data data2;
    input team $ points rebounds;
    datalines;
F 26 8
G 30 4
H 27 9
I 21 12
J 20 6
;
run;

/*view datasets*/
proc print data=data1;
proc print data=data2;

We can use the following PROC APPEND statement to append the values of data2 to the end of data1:

/*append data2 to end of data1*/
proc append
    base=data1
    data=data2;
run;

/*view updated data1*/
proc print data=data1;

We can see that the values of data2 have been added to the end of data1. The dataset data1 now contains 10 total observations.

It’s important to note that you’ll receive the following error message if you attempt to use PROC APPEND when the two datasets have different column names:

ERROR: No appending done because of anomalies listed above.
       Use FORCE option to append these files.

In this situation, you can either change the column names to match or you can use the force argument to force the append procedure.

For example, suppose the second dataset had a variable name of “rebound” instead of “rebounds.”

We could use the following syntax to append the two datasets and force them to be appended:

/*append data2 to end of data1*/
proc append
    base=data1
    data=data2
    force;
run;

/*view updated data1*/
proc print data=data1;

Notice that data2 has been appended to data1, but the values in the rebounds column are empty for the appended dataset.

Note: You can find the complete documentation for PROC APPEND here.

Additional Resources

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

How to Use Proc Summary in SAS
How to Use Proc Tabulate in SAS
How to Use Proc Rank 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