Concatenating: Details

Concatenating Syntax

Another way to combine SAS data sets with the SET statement is concatenating, which appends the observations from one data set to another data set. To concatenate SAS data sets, you specify a list of data set names in the SET statement.
Syntax, DATA step for concatenating:
DATA output-SAS-data-set;
SET SAS-data-set-1 SAS-data-set-2;
RUN;
  • output-SAS-data-set names the data set to be created.
  • SAS-data-set-1 and SAS-data-set-2 specify the data sets to be read.

How Concatenating Selects Data

When a program concatenates data sets, all of the observations are read from the first data set listed in the SET statement. Then all of the observations are read from the second data set listed, and so on, until all of the listed data sets have been read. The new data set contains all of the variables and observations from all of the input data sets.
data concat; 
   set a c; 
run;
Figure 13.4 How Concatenating Selects
How Concatenating Selects Data
Notice that A and C contain a common variable named Num:
  • Both instances of Num (or any common variable) must have the same type attribute, or SAS stops processing the DATA step and issues an error message stating that the variables are incompatible.
  • However, if the length attribute is different, SAS takes the length from the first data set that contains the variable. In this case, the length of Num in A determines the length of Num in Concat.
  • The same is true for the label, format, and informat attributes: If any of these attributes are different, SAS takes the attribute from the first data set that contains the variable with that attribute.

Example: Using Concatenating to Combine Data Sets

The following DATA step creates Clinic.Concat by concatenating Clinic.Therapy2012 and Clinic.Therapy2013. Each data set contains 12 observations.
data clinic.concat; 
   set clinic.therapy2012 clinic.therapy2013; 
run; 
The first 12 observations in the new output data set Clinic.Concat were read from Clinic.Therapy2012, and the last 12 observations were read from Clinic.Therapy2013.
Figure 13.5 Example: Concatenating (partial output)
Example: Concatenating (Partial Output)
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.15.186.79