One-to-One Reading: Details

One-to-One Reading Syntax

Use multiple SET statements in a DATA step to combine data sets. One-to-one reading combines rows from two or more data sets by creating rows that contain all of the columns from each contributing data set. Rows are combined based on their relative position in each data set. That is, the first row in one data set is combined with the first in the other, and so on. The data program stops after it has read the last row from the smallest data set.
Syntax, DATA step for one-to-one reading:
DATA output-SAS-data-set;
SET SAS-data-set-1;
SET 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 One-to-One Reading Selects Data

The following statements are true when you perform one-to-one reading:
  • The new data set contains all the variables from all the input data sets. If the data sets contain variables that have the same names, the values that are read from the last data set overwrite the values that were read from earlier data sets.
  • The number of observations in the new data set is the number of observations in the smallest original data set. Observations are combined based on their relative position in each data set. That is, the first observation in one data set is joined with the first observation in the other, and so on. The DATA step stops after it has read the last observation from the smallest data set.
data one2one; 
  set a; 
  set b; 
run;
Figure 10.1 One-to-One Reading
One-to-One Reading

How One-to-One Reading Works

Here is a simple example of one-to-one reading.
data one2one; 
  set a; 
  set b; 
run;
  1. The first SET statement reads the first observation from data set A into the PDV.
    First SET statement
  2. The second SET statement reads the first observation from data set B into the PDV, and SAS writes the contents of the PDV to the new data set. The value for Num from data set B overwrites the value for Num from data set A.
    The second SET statement
  3. The first SET statement reads from data set A into the PDV.
    The second SET statement
  4. The second SET statement reads the second observation from data set B, and SAS writes the contents of the PDV to the new data set. The value for Num from data set B overwrites the value for Num from data set A.
    The second SET statement reads the second observation
  5. The first SET statement reads the third observation from data set A into the PDV.
    The first SET statement reads the third observation
  6. The second SET statement reads the end of file in data set B, which stops the DATA step processing with no further output written to the data set. The last observation in data set A is read into the PDV, but it is not written to the output data set.
Final Combined SAS Data Set

Example: Using One-to-One Reading to Combine Data Sets

In the following example, you have basic patient data in Cert.Patients that you want to combine with other patient data that is stored in Cert.Measure. The height and weight data is stored in the data set Cert.Measure. Both data sets are sorted by the variable ID.
Notice that Cert.Patients contains eleven observations in which the patient age is less than 60, and Cert.Measure contains six observations.
Figure 10.2 Example: One-to-One Reading
Example: One-to-One Reading
To subset observations from the first data set and combine them with observations from the second data set, you can submit the following program:
data work.one2one; 
  set cert.patients; 
  if age<60; 
  set cert.measure; 
run;
The resulting data set, Work.One2one, contains six observations (the number of observations read from the smallest data set, which is Cert.Measure). The last observation in Cert.Patients is not written to the data set because the second SET statement reaches an end-of-file, which stops the DATA step processing.
Figure 10.3 The Resulting Data Set for One-to-One Reading Example
The Resulting Data Set for One-to-One Reading Example
Last updated: August 23, 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.74.231