PROC DATASETS - APPEND Statement

<< Back to the PROC DATASETS Page.

Suppose, for some business need one has to append the observations from one dataset to another. There may be various ways to carry out this task. like using PROC APPEND, or just specifying the dataset names in SET statement.

And of course using PROC DATASETS - APPEND statement.

EXAMPLE:

Before moving to the actual demonstrations we will set up the environment.

Following code declares one library and creates some SAS datasets inside; just for demo purpose.

Setting up the Background

SAS Code:

libname xyz 'D:\SAS_Datasets\';

data xyz.a;

amt = 5600;

run;

data xyz.b;

run;

data xyz.c;

amt = 5600;

run;

data xyz.d;

amt = 5600;

run;

SYNTAX:

proc datasets lib="libname";

APPEND out= master_dataset_name data=dataset_to_be_appended;

quit;

While the PROC DATASETS will just append the second dataset to first one without making iterations.

PROC DATASET - APPEND statement is certainly advantageous over the SET statement method. Because while using multiple datasets with SET statement, datastep processing will unnecessarily iterate through each observation of both the datasets.

SAS Code in the following example is trying to append observations from dataset C to the observations of dataset B.

SAS Code: PROC DATASETS - APPEND Statement

libname xyz 'D:\SAS_Datasets\';

proc datasets lib=xyz;

append out= b data=c;

quit;

proc contents data=xyz.b;

run;

From the PROC CONTENTS output we can observe that number of observations in dataset B has become 2 after appending one observation from dataset C.

Following is the output of the code above. (Note, this is just a part of the actual output).

OUTPUT: PROC DATASETS - APPEND Statement

The CONTENTS Procedure