Using PROC APPEND to Join Similar Data Sets - SAS Programming

Depending on the circumstances,this method can give you a tremendous increase in efficiency.Your goal is to join two (or more) similar data sets. When we say "similar," we mean that the data sets have the same variables and variable attributes.If you are adding records to a large master file from a small update file, the savings can be even greater.Compare the following two programs:

Example – INEFFICIENT

DATA UPDATE;
SET MASTER NEW?
RUN;

Here you create data set UPDATE by processing data sets MASTER and NEW sequentially.You go through all of the overhead of processing both data sets. This is unnecessary if the goal is simply to append one data set to another.

Example – EFFICIENT

PROC APPEND BASE=MASTER DATA=NEW; RUN;

In the efficient method, you merely add the observations of NEW to those of MASTER without processing either data set. Before running this procedure, you should run PROC CONTENTS on both data sets to be sure that they contain the same variables with the same attributes.If this is not true, you can use the FORCE option which will usually accomplish this, but be careful.You should fully understand this option before using it.Consult the SAS documentation for your operating system.

You can also restrict which observations from the DATA= data set are appended to the BASE= data set by using a WHERE= data set option. For example:

PROC APPEND
BASE=MASTER
DATA=NEW(WHERE=(AGE GE 4 0 ) ) ;
RUN;

You can also accomplish the exact same goal by using PROC DATASETS:

LIBNAME libref 'SAS_data_library';
PROC DATASETS LIBRARY=libref;
APPEND BASE=MASTER DATA=NEW;
RUN;

or

LIBNAME libref 'SAS_data_library';
PROC DATASETS LIBRARY=libref;
APPEND BASE=MASTER DATA=NEW(WHERE=(AGE GE 40));
RUN;

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

SAS Programming Topics