Match merges
Safely create a single data set from the information in the two data sets. Use a BY statement in the data step to specify the index variable(s) that should be used to match up the observations.
Title 'Like Example 4 in C&P Chapter 3'; Proc Sort data=GenYear; BY Subj; Proc Sort data=HtWt; BY Subj; Data Survey12; Merge GenYear HtWt; BY Subj; Proc Print; ID Subj;
The final output is fine.
Like Example 4 in C&P Chapter 3 SUBJ GENDER YEAR HEIGHT WEIGHT 1 M 91 68 155 5 F 92 102 63 7 F 90 72 205 8 M 91 250 70 9 M 93 66 120
The way it works: The BY statement in the Data step does not sort the data.
The BY statement says that the data set(s) are sorted by its variables.
SAS does not care how the proper order was accomplished-there are lots of ways to reorder a data set-all that matters is that the order is as is specified in the BY statement.