RENAME= Data Set Option

Changes the name of a variable.

Valid in: DATA step and PROC steps
Category: Variable Control

Syntax

Syntax Description

old-name

is the variable that you want to rename.

new-name

is the new name of the variable. It must be a valid SAS name.

Details

If you use the RENAME= data set option when you create a data set, the new variable name is included in the output data set. If you use RENAME= on an input data set, the new name is used in DATA step programming statements.
If you use RENAME= on an input data set that is used in a SAS procedure, SAS changes the name of the variable in that procedure. If you use RENAME= with WHERE processing such as a WHERE statement or a WHERE= data set option, the new name is applied before the data is processed. You must use the new name in the WHERE expression.
Use RENAME= in the same DATA step with either the DROP= data set option or the KEEP= data set option. The DROP= and KEEP= data set options are applied before RENAME=. You must use the old name in the DROP= and KEEP= data set options. You cannot drop and rename the same variable in the same statement.
Note: The RENAME= data set option has an effect only on data sets that are opened in output mode.
Use the RENAME statement or the RENAME= data set option when program logic requires that you rename variables. An example is two input data sets that have variables with the same name. To rename variables as a file management task, use the DATASETS procedure.
You must use the RENAME= data set option on the input data set or data sets to rename variables before processing begins.

Comparisons

The RENAME= data set option differs from the RENAME statement in these ways:
  • You can use the RENAME= data set option, not the RENAME statement, in PROC steps.
  • You must use the RENAME= data set option to rename different variables in different data sets. The RENAME statement applies to all output data sets.

Examples

Example 1: Renaming a Variable at Time of Output

This example uses RENAME= in the DATA statement to show that the variable is renamed when it is written to the output data set. The variable keeps its original name, X, during DATA step processing.
data one;
  input x y z;
  datalines;
24 595 439
243 343 034
;
proc print data=one;
run;

data two(rename=(x=keys));
   set one;
   z=x+y; 
run;
proc print data=two;
run;
Data Sets One and Two
Data Set One
Data Set Two

Example 2: Renaming a Variable at Time of Input

This example renames variable X to a variable named KEYS in the SET statement, before DATA step processing.
data three;
   set one(rename=(x=keys));
   z=keys+y;
run;

proc print data=three;
run;
Data Set Three
Data Set Three

Example 3: Renaming a Variable for a SAS Procedure with WHERE Processing

This example renames variable Score1 to a variable named Score2 for the PRINT procedure. Because the new name is applied before the data is processed, the new name must be specified in the WHERE statement.
data test;
  input score1;
  datalines;
26 
76
86 
56
;

proc print data=test (rename=(score1=score2));
   where score2 gt 75;
run;
Data Set Test
Data Set Test

See Also

Statement:
RENAME Statement in SAS Statements: Reference
Procedure:
DATASETS Procedure in Base SAS Procedures Guide