Interleaving: Details

Interleaving Syntax

When you use a BY statement to concatenate data sets, the result is interleaving. Interleaving intersperses observations from two or more data sets, based on one or more common variables.
To interleave SAS data sets, specify a list of data set names in the SET statement, and specify one or more BY variables in the BY statement.
Syntax, DATA step for interleaving:
DATA output-SAS-data-set;
SET SAS-data-set-1 SAS-data-set-2;
BY variable(s);
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.
  • variable(s) specifies one or more variables that are used to interleave observations.
Tip
Specify any number of data sets in the SET statement. Each input data set must be sorted or indexed in ascending order based on the BY variable or variables.

How Interleaving Selects Data

When SAS interleaves data sets, observations in each BY group in each data set in the SET statement are read sequentially, in the order in which the data sets and BY variables are listed, until all observations have been processed. The new data set includes all the variables from all the input data sets, and it contains the total number of observations from all input data sets.
data interlv; 
     set c d; 
     by num; 
run;
Figure 13.9 How Interleaving Selects Data
How Interleaving Selects Data

Example: Using Interleaving to Combine Data Sets

The following DATA step creates Clinic.Interlv by interleaving Clinic.Therapy2012 and Clinic.Therapy2013.
data clinic.interlv; 
   set clinic.therapy2012 clinic.therapy2013; 
   by month; 
run;
Below is the listing of Clinic.Interlv. Notice that, unlike the previous example, observations are interleaved by month instead of being concatenated.
Figure 13.10 Example: How Interleaving Selects Data (partial output)
Example: How Interleaving Selects Data (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
18.117.187.62