Previous PageNext Page

Possible problems: Identical variable names
The BY variables must exist in both data sets in the MERGE statement. What if there are other variables with the same name in both data sets?

Proc Sort data=GenYear (RENAME= (Year=Height));
     BY Subj;
Proc Sort data=HtWt;
     BY Subj;
Data Survey12;
     Merge GenYear HtWt;
     BY Subj;
Proc Print;
     ID Subj;

The RENAME= option is an option of the data set name (like DROP= and KEEP=). It makes the data set look as though the old variable name, Year, is a new variable name, Height).
Note: If you use both RENAME and DROP or KEEP together, be sure to use the old variable names in the DROP or KEEP statements - think about it.

As the Proc Print output shows, there is only one variable called HEIGHT.

SUBJ    GENDER    HEIGHT    WEIGHT

  1       M          68       155
  5       M          102       63
  7       F          72       205
  8       M          91        70
  9       M          66       120

The last values of the variable written into RAM (the program data vector) are all that is remembered. The values of HEIGHT in GenYear (actually the variable YEAR) were overwritten by the values of HEIGHT from HtWt.

Previous PageTable Of ContentsNext Page