Suppose you have basic patient data (ID, sex, and age)
in the data set Clinic.Patients and want to combine it with other
patient data (height and weight) for patients under age 60. The height
and weight data is stored in the data set Clinic.Measure. Both data
sets are sorted by the variable ID.
Notice that Clinic.Patients
contains seven observations in which the patient age is less than
60, and Clinic.Measure contains six observations.
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 clinic.one2one;
set clinic.patients;
if age<60;
set clinic.measure;
run;
The resulting data set,
Clinic.One2one, contains six observations (the number of observations
read from the smallest data set, which is Clinic.Measure). The last
observation in Clinic.Patients is not written to the data set because
the second SET statement reaches an end-of-file, which stops the DATA
step processing.