BookmarkSubscribeRSS Feed

The RENAME statement (and dataset options) can now handle renaming lists of variable if both the SOURCE and TARGET names are simple numerical suffix lists.  So I could write statements like these:

rename old1-old5=new1-new5 ;
rename old1-old5=new6-new10 ;
rename old1-old5=old2-old6;

But frequently we have other lists of variable names, including just simple space delimited names like you would use in any SAS statement.  I would request that we enhance the RENAME statement to allow the addition of extra parenthesis to rename lists of variables.  So things like this:

rename (a b c d e)=(name age sex height weight);
rename old1-old5=(a b c d e);
rename a--e=var1-var5 ;
rename (name age sex height weight)=var1-var5 ;
rename new:=var1-var5;

 

4 Comments
Astounding
PROC Star

Definitely overdue.  I might add the ability to use variable lists in nonstandard ways, along these lines:

 

rename in_1_dat - in_99_dat = in_1_sasdate - in_99_sasdate;

 

I'm not expecting it to be easy, but it would be useful.

Tom
Super User
Super User

There might be some confusion with the RENAME() function, but the = required by the RENAME statement should make it possible to tell the difference. 

A bigger problem might come if a data step had defined an array named RENAME.

For example you can currently write code like this to replace the value of the first variable in the array with the value of the second variable in the array. 

array rename (5);
old=1;
new=2;
rename (old)=(new) ;

When the number of parameters (tokens) is unsuitable for an assignment to an array reference then it should be clear it is a RENAME statement.

Otherwise assume they meant the array reference.  The same way that it does when you make an array named N or MEAN or any other SAS function.

 

PGStats
Opal | Level 21

How about prefix replacement:

 

rename old: = new_: ; /* Change prefix */
rename _: = : ; /* Remove prefix */
Tom
Super User
Super User

Prefixes would be difficult given the way they currently work.  They find existing names that start with those letters, but for rename you generally need names that do NOT exist.  Maybe a syntax like this instead:

rename OLD =: NEW ;

that uses the : as a modifier to the = in a similar way that it is used with = and other comparison operators.