Chapter Contents

Previous

Next
RENAME=

RENAME=



Changes the name of a variable

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


Syntax
Syntax Description
Details
Comparisons
Examples
Example 1: Renaming a Variable at Time of Output
Example 2: Renaming a Variable at Time of Input
See Also

Syntax

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

Syntax Description

old-name
the variable you want to rename.

new-name
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. The list of variables to rename must be enclosed in parentheses:

proc print data=test(rename=(score1=score2));

If you use RENAME= in the same DATA step with either the DROP= or the KEEP= data set option, the DROP= and the KEEP= data set options are applied before RENAME=. Thus, use old-name in the DROP= and KEEP= data set options. You cannot drop and rename the same variable in the same statement.


Comparisons


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 at the time it is written to the output data set. The variable keeps its original name, X, during the DATA step processing:

data two(rename=(x=keys));
   set one;
   z=x+y; 
run;

Example 2: Renaming a Variable at Time of Input

This example renames variable X to a variable named KEYS in the SET statement, which is a rename before DATA step processing. KEYS, not X, is the name to use for the variable for DATA step processing.

data three;
   set one(rename=(x=keys));
   z=keys+y;
run;

See Also

Data Set Options:

DROP=
KEEP=

Statements:

RENAME

"The DATASETS Procedure" in the SAS Procedures Guide


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.