Cornell University Cornell University CISER

CISER Computing

Match-Merging when By-Variable Names are Different

Q.  I am having difficulty with renaming a variable in a SAS data set. I am attempting to match-merge two files on a subject ID code. Unfortunately, in the two data sets this ID code has a different variable name. Do I really need to rename variables in my data before I can perform the merge. Any suggestions you have would be helpful.

A.  If you'd like to do a match-merge in SAS, you actually don't have to rename the key variables permanently. You can use a RENAME option in your MERGE statement to temporarily rename variables. Let's say dataset A contains a variable called ID and dataset B has a similar variable, except that it is called PIN. The following code will allow you to match-merge the files:

data new;
     merge a b (rename=(pin=id));
     by id; run;