Return to Archive

SAS Tip of the Month
October 2007

This can be quite tricky, and does depend on where in the datastep the RENAME statement is placed.

Lets look at the following example:

   *** Creating a dataset;
   data ourdata;
      infile cards;
      input x y z;
   1 2 3
   4 5 6
   *** Modifying the variable names;
   data ourdata_modified;
      set ourdata (rename=(x=a));
      rename y=b;
      if a=1 then do;
         *More steps;
      if y=5 then do;
         *More steps;

In the example, the variable x is renamed to a PRIOR to entry into the datastep, meaning that the variable a is known and can be manipulated within the step. This is different to the variable y - this is renamed as the observation is passed into the dataset OURDATA_MODIFIED, meaning that the variable y is still available inside the datastep for manipulation.

Updated October 1, 2007