RENAME= Data Set Option

Changes the name of a column.

Valid in: DATA and PROC steps
Category: Variable Control
Supports: All

Syntax

RENAME=(old-name-1=new-name-1< ...old-name-n=new-name-n> )

Syntax Description

old-name

the column that you want to rename.

new-name

the new name of the column. It must be a valid SAS name.

Details

If you use the RENAME= data set option when you create a data set, the new column 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 column in that procedure. If you use RENAME= along with WHERE processing such as a WHERE statement or WHERE= data set option, the new name is applied before the data is processed. You must use the new name in the WHERE expression.
If you use RENAME= in the same DATA step with either the DROP= or the KEEP= data set option, the DROP= or KEEP= data set option is applied before RENAME=. You must use the old name in the DROP= and KEEP= data set options. You cannot drop and rename the same column in the same statement.
Note: The RENAME= data set option has an effect only on data sets opened in output mode.

Comparisons

  • The RENAME= data set option differs from the RENAME statement in the following ways:
    • The RENAME= data set option can be used in PROC steps and the RENAME statement cannot.
    • The RENAME statement applies to all output data sets. If you want to rename different columns in different data sets, you must use the RENAME= data set option.
    • To rename columns before processing begins, you must use a RENAME= data set option on the input data set or data sets.
  • Use the RENAME statement or the RENAME= data set option when program logic requires that you rename columns such as two input data sets that have columns with the same name.

Examples

Example 1: Renaming a Column at Time of Output

This example uses RENAME= in the DATA statement to show that the column is renamed at the time it is written to the output data set. The column keeps its original name, X, during the DATA step processing:
data myfiles.one;
  input x y z;
  datalines;
24 595 439
243 343 034
;
data myfiles.two(rename=(x=keys));
   set one;
   z=x+y;
run;

Example 2: Renaming a Column at Time of Input

This example renames column X to a column named Keys in the SET statement, which is a rename before DATA step processing. Keys, not X, is the name to use for the column for DATA step processing.
data myfiles.three;
   set one(rename=(x=keys));
   z=keys+y;
run;

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

This example renames column Score1 to a column 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.
proc print data=test (rename=(score1=score2));
   where score2 gt 75;
run;