RENAME Statement


Specifies new names for variables in output SAS data sets

Valid: in a DATA step

Category: Information

Type: Declarative

Syntax

RENAME old- name -1 = new-name-1 < old-name-n = new-name-n >;

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 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.

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:

    • 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 Option:

  • RENAME= Data Set Option on page 46




SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 704

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net