Statements |
Valid: | in a DATA step |
Category: | Information |
Type: | Declarative |
Syntax | |
Arguments | |
Details | |
Comparisons | |
Examples | |
See Also |
Syntax |
RENAME old-name-1=new-name-1 . . . <old-name-n=new-name-n>; |
specifies the name of a variable or variable list as it appears in the input data set, or in the current DATA step for newly created variables.
Details |
The RENAME statement allows you to change the names of one or more variables, variables in a list, or a combination of variables and variable lists. The new variable names are written to the output data set only. Use the old variable names in programming statements for the current DATA step. RENAME applies to all output data sets.
Note: The RENAME statement has an effect on data sets opened in output mode only.
Comparisons |
RENAME cannot be used in PROC steps, but the RENAME= data set option can.
The RENAME= data set option allows you to specify the variables you want to rename for each input or output data set. Use it in input data sets to rename variables before processing.
If you use the RENAME= data set option in an output data set, you must continue to use the old variable names in programming statements for the current DATA step. After your output data is created, you can use the new variable names.
The RENAME= data set option in the SET statement renames variables in the input data set. You can use the new names in programming statements for the current DATA step.
To rename variables as a file management task, use the DATASETS procedure or access the variables through the SAS windowing interface. These methods are simpler and do not require DATA step processing.
Examples |
These examples show the correct syntax for renaming variables using the RENAME statement:
This example uses the old name of the variable in program statements. The variable Olddept is named Newdept in the output data set, and the variable Oldaccount is named Newaccount.
rename Olddept=Newdept Oldaccount=Newaccount; if Oldaccount>5000; keep Olddept Oldaccount items volume;
This example uses the old name OLDACCNT in the program statements. However, the new name NEWACCNT is used in the DATA statement because SAS applies the RENAME statement before it applies the KEEP= data set option.
data market(keep=newdept newaccnt items volume); rename olddept=newdept oldaccnt=newaccnt; set sales; if oldaccnt>5000; run;
The following example uses both a variable and a variable list to rename variables. New variable names appear in the output data set.
data temp; input (score1-score3) (2.,+1) name $; rename name=Firstname score1-score3=Newscore1-Newscore3; datalines; 12 24 36 Lisa 22 44 66 Fran ;
See Also |
|
Copyright © 2011 by SAS Institute Inc., Cary, NC, USA. All rights reserved.