SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Merging SAS Data Sets
Renaming Variables


To prevent overwriting, you can rename variables using the RENAME= data set option in the MERGE statement.


General form, RENAME= data set option:
(RENAME=(old-variable-name=new-variable-name))   

where

  • the RENAME= option, in parentheses, follows the name of each data set that contains one or more variables to be renamed
  • old-variable-name names the variable to be renamed
  • new-variable-name specifies the new name for the variable.
NOTE: You can rename any number of variables in each occurrence of the RENAME= option.

You can also use RENAME= to rename variables in the output data set specified in the DATA statement.


In the following example, the RENAME= option renames the variable Date in Clinic.Demog to BirthDate, and the variable Date in Clinic.Visit to VisitDate.
     data clinic.combined;       
        merge clinic.demog(rename=(date=BirthDate))
              clinic.visit(rename=(date=VisitDate)); 
        by id;
     run;
     proc print data=clinic.combined;
     run;

The following output shows the effect of the RENAME= option.


Obs ID Age Sex BirthDate Visit SysBP DiasBP Weight VisitDate
1 A001 21 m 05/22/75 1 140 85 195 11/05/98
2 A001 21 m 05/22/75 2 138 90 198 10/13/98
3 A001 21 m 05/22/75 3 145 95 200 07/04/98
4 A002 32 m 06/15/63 1 121 75 168 04/14/98
5 A003 24 f 08/17/72 1 118 68 125 08/12/98
6 A003 24 f 08/17/72 2 112 65 123 08/21/98
7 A004 .   03/27/69 1 143 86 204 03/30/98
8 A005 44 f 02/24/52 1 132 76 174 02/27/98
9 A005 44 f 02/24/52 2 132 78 175 07/11/98
10 A005 44 f 02/24/52 3 134 78 176 04/16/98
11 A007 39 m 11/11/57   . . . .
12 A008 .   . 1 126 80 182 05/22/98



back||next


Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.

Terms of Use & Legal Information | Privacy Statement