Renaming Variables

The Basics of Renaming Variables

DATA step match-merging overwrites values of the like-named variable in the first data set in which it appears with values of the like-named variable in subsequent data sets.
Consider Clinic.Demog, which contains the variable Date (date of birth), and Clinic.Visit, which also contains Date (date of the clinic visit in 1998). The DATA step below overwrites the date of birth with the date of the clinic visit.
data clinic.merged; 
   merge clinic.demog clinic.visit; 
   by id; 
run; 
proc print data=clinic.merged; 
run;
The following output shows the effects of overwriting the values of a variable in the Clinic.Merged data set. In most observations, the date is now the date of the clinic visit. In observation 11, the date is still the birthdate because Clinic.Visit did not contain a matching ID value and did not contribute to the observation.
Figure 13.18 Renaming Variables
Renaming Variables

RENAME Statement Syntax

To prevent overwriting, you can rename variables by using the RENAME= data set option in the MERGE statement.
Syntax, RENAME= data set option:
(RENAME=(old-variable-name=new-variable-name))
  • the RENAME= option, in parentheses, follows the name of each data set that contains one or more variables to be renamed
  • old-variable-name specifies the variable to be renamed.
  • new-variable-name specifies the new name for the variable.
Tip
Use RENAME= to rename variables in the SET statement or in the output data set that is specified in the DATA statement.

Example: Renaming Variables

In the following example, the RENAME= option renames the variable Date in Clinic.Demog to BirthDate, and it renames the variable Date in Clinic.Visit to VisitDate.
data clinic.merged;        
   merge clinic.demog (rename=(date=BirthDate)) 
         clinic.visit (rename=(date=VisitDate)); 
   by id; 
run; 
proc print data=clinic.merged; 
run;
The following output shows the effect of the RENAME= option.
Figure 13.19 Output for RENAME= Option
Output for RENAME= Option
Last updated: January 10, 2018
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.136.142