Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Renaming a list of variables

Status
Not open for further replies.

ntilton

Technical User
Oct 28, 2010
2
US
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?

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

Code:
data have ;
   set sashelp.class ;
   run;
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 ;

HTH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top