Appending: Details

The APPEND Procedure

Another way to combine SAS data sets is to append one data set to another using the APPEND procedure. Although appending and concatenating are similar, there are some important differences between the two methods. Whereas the DATA step creates an entirely new data set when concatenating, PROC APPEND simply adds the observations of one data set to the end of a “master” (or BASE) data set. SAS does not create a new data set nor does it read the base data set when executing the APPEND procedure.
To append SAS data sets, you specify a BASE= data set, which is the data set to which observations are added and then specify a DATA= data set, which is the data set containing the observations that are added to the base data set. The data set specified with DATA= is the only one of the two data sets that SAS actually reads.
Syntax, APPEND procedure:
PROC APPEND BASE=SAS-data-set
DATA=SAS-data-set;
RUN;
  • BASE= names the data set to which observations are added.
  • DATA= names the data set containing observations that are added to the base data set.
For example, the following PROC APPEND statement appends the observations in data set B to the end of data set A:
proc append base=A
            data=B; 
run;
Figure 13.6 How PROC APPEND Appends Data
How PROC APPEND Appends Data

Requirements for the APPEND Procedure

Here are the requirements for appending one data set to another:
  • Only two data sets can be used at a time in one step.
  • The variable information in the descriptor portion of the base data set cannot change.
Note: The final data set is the original data set with appended observations. The observations in the BASE= data set are not read.

Example: Using the PROC APPEND Statement to Combine Data Sets

The following PROC APPEND statement appends the data set Totals2011 to the base data set Totals2005. The two data sets are like-structured data sets: that is, both data sets have the same variable information.
proc append base=totals2005 data=totals2011; 
run; 
Below is the listing of Totals2005. The first four observations already existed in totals2005, and the last four observations were read from totals2011 and added to totals2005.
Figure 13.7 Example: PROC APPEND
Example: PROC APPEND

Using the FORCE Option with Unlike-Structured Data Sets

In order to use PROC APPEND with data sets that have unmatching variable definitions, you can use the FORCE option in the PROC APPEND statement.
Syntax, APPEND procedure with the FORCE option:
PROC APPEND BASE=SAS-data-set
DATA=SAS-data-set FORCE;
RUN;
The FORCE option is needed when the DATA= data set contains variables that meet any one of the following criteria:
  • They are not in the BASE= data set.
  • They are variables of a different type (for example, character or numeric).
  • They are longer than the variables in the BASE= data set.
If the length of a variable is longer in the DATA= data set than in the BASE= data set, SAS truncates values from the DATA= data set to fit them into the length that is specified in the BASE= data set.
If the type of a variable in the DATA= data set is different from that in the BASE= data set, SAS replaces all values for the variable in the DATA= data set with missing values and keeps the variable type of the variable specified in the BASE= data set.
If the BASE= data set contains a variable that is not in the DATA= data set, the observations are appended, but the observations from the DATA= data set have a missing value for the variable that was not present in the DATA= data set. If the DATA= data set contains a variable that is not in the BASE= data set, the variable is dropped from the output.

Example: Appending with FORCE Option

proc append  base=sasuser.patients
             data=clinic.append force; 
run; 
Figure 13.8 Example: PROC APPEND with FORCE Option
Example: PROC APPEND with FORCE Option
Last updated: January 10, 2018
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.134.151