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 Cert.Demog, which contains the variable Date (date of birth), and Cert.Visit, which also contains Date (date of the clinic visit in 2009). The DATA step below overwrites the date of birth with the date of the clinic visit.
data work.merged; 
  merge cert.demog cert.visit; 
  by id; 
run; 
proc print data=work.merged; 
run;
The following output shows the effects of overwriting the values of a variable in the Work.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 Cert.Visit did not contain a matching ID value and did not contribute to the observation.
Figure 10.13 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 Cert.Demog to BirthDate, and it renames the variable Date in Cert.Visit to VisitDate.
data work.merged;        
  merge cert.demog (rename=(date=BirthDate)) 
    cert.visit (rename=(date=VisitDate)); 
    by id; 
run; 
proc print data=work.merged; 
run;
The following output shows the effect of the RENAME= option.
Figure 10.14 Output for RENAME= Option
Output for RENAME= Option
Last updated: August 23, 2018
..................Content has been hidden....................

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