Concatenating SAS data sets with the APPEND procedure

The APPEND procedure is an efficient method for concatenating observations from a smaller data set to a larger data set. The BASE= data set option is reserved for the larger of the two data sets with the DATA= option for the smaller data set. Essentially, the APPEND procedure avoids reading any observations in the BASE= data set by positioning the record pointer at the end of the BASE= data set.

If no additional processing is necessary, using PROC APPEND or the APPEND statement in PROC DATASETS is more efficient than using a DATA step to concatenate data sets.

Each observation from the smaller data set is then applied one at a time to the end of the BASE= data set. In the next example, the BASE= data set identifies a larger data set called MASTER and the DATA= data set identifies the smaller SOURCEDATA data set.

When one or more variables in the input data set (DATA=) are not present in the BASE= data set, an optional FORCE option can be specified as an option with the PROC APPEND statement to prevent a syntax error

PROC APPEND
BASE=master
DATA=sourcedata;
RUN;

WARNING: Variable charvar has different lengths on BASE and DATA files (BASE 25 DATA 30).
ERROR: No appending done because of anomalies listed above. Use FORCE option to append these files.

As the LOG message suggest, no appending is done and use of the FORCE option is necessary to append the input files. The consequent required syntax to correct this issue would look like this:

PROC APPEND
BASE=master
DATA=sourcedata force;
RUN;

WARNING: Variable charvar has different lengths on BASE and DATA files (BASE 25 DATA 30).
NOTE: FORCE is specified, so dropping/truncating will occur.

When two or more data sets need to be concatenated, multiple APPEND procedures are issued. In the next example, two separate PROC APPEND steps are specified to concatenate the two smaller data sets (mysasdata1 and mysasdata2) at the end of the larger BASE= data set.

PROC APPEND
BASE=master
DATA=mysasdata1;
RUN;

PROC APPEND
BASE=master
DATA=mysasdata2;
RUN;

You cannot use PROC APPEND to add observations to a SAS data set in a sequential library

Reference: SAS 9.2 Language Reference Concepts 2nd edition

Advertisements