RENAME Statement

Specifies new names for variables in output SAS data sets.
Valid in: DATA step
Category: Information
Type: Declarative

Syntax

Arguments

old-name
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.
new-name
specifies the name or list to use in the output data set.

Details

The RENAME statement enables 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 enables you to specify the variables that 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.

Example: Renaming Data Set Variables

  • These examples show the correct syntax for renaming variables using the RENAME statement:
    rename street=address;
    rename time1=temp1 time2=temp2 time3=temp3;
    rename name=Firstname score1-score3=Newscore1-Newscore3; 
  • 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

Data Set Options:
RENAME= Data Set Option in SAS Data Set Options: Reference