Printer-friendly versionPrinter-friendly version

As is the case when combining data sets by other methods, data set options, such as RENAME=, IN=, DROP=, and KEEP=, can be used when match-merging data sets. In this section, we'll look at an example that uses the RENAME= option to rename variable names that are shared by the data steps to be merged.

Example 16.8. The following program uses the RENAME= option to rename the v_date variables in the demogtwo and statustwo data sets, so that when they are merged into a new data set called patientstwo, both visit dates are preserved:

When reviewing the first two DATA steps, in which we tell SAS to read in the demogtwo and statustwo data sets, note that both of the data sets contain a date variable called v_date. The third DATA step tells SAS to merge the demogtwo and statustwo data sets by the subj variable, and when doing so change the name of the v_date variable in the demogtwo data set to demogdate and the name of the v_date variable in the statustwo data set to statusdate. Because of this renaming that takes place, rather than the program data vector looking like this:

it looks like this:

Therefore, the merge reduces to a simple match-merge in which all of the values in the input data sets have a rightful position in the program data vector and are therefore preserved.

Launch and run the program, and review the output to convince yourself that the demogtwo and statustwo data sets are merged by subj successfully, and that the values in each input data set are preserved in the output data set patientstwo.