Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Renaming a list of variables

Renaming a list of variables

Renaming a list of variables

Hi. I need to create a new data set from an original data set (using the SET statement in the data step), but most of the variables need to be renamed using the prefix "td" and the original variable name.  Unfortunately, the variables in the original data set aren't a numbered list (i.e. var1, var2, ... var n)

Is there a way to do this without individually renaming each of the variables?


RE: Renaming a list of variables

You could use the PROC contents and save the out file. Then write a macro or even some base SAS code that would loop through the variables and generate the rename code. Then execute the code in a call execute.

If you need more info let me know. If I have time later I can try and code it for you.

RE: Renaming a list of variables

As you have already noted, given the names of your variable, you cannot rename with a variable list.

I would consider using a combination of SQL and the dictionary tables to generate the rename code.

Example using sashelp.class


data have ;
   set sashelp.class ;
proc sql noprint;
   select cats( name,'=td',name)
   into: rcode separated by ' '
   from dictionary.columns where libname='WORK' and memname='HAVE';
   quit ;
%put &rcode ;
proc datasets library=work ;
   modify have ;
   rename &rcode ;
   run ;
proc contents data=have short ;run ;


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close