BookmarkSubscribeRSS Feed
chandler
Fluorite | Level 6

I have a bunch of datasets that have been recreated on a new server.  However, the variable names now have a four letter prefix (table name_variable name).

In order for my legacy programs to read these datasets in the new server, I want to rename to variables to display without the table name prefix, thus, saving me from recoding all of my programs.

1 REPLY 1
Tom
Super User Tom
Super User

Use the RENAME statement (which will work for actual SAS datasets).

Get the list of variables. Generate the RENAME statement.  

You do them all at once by using PROC DATASETS.

proc contents data=mylib._all_ noprint out=contents; run;

filename code temp;
data _null_;
  set contents;
  by memname;
  file code;
  if first.memname then put 'modify ' memname ';' / @3 'rename ' ;
  length old new $70 ;
  old=nliteral(name);
  new=nliteral(substr(name,5));
  put @5 old '=' new ;
  if last.memname then put @3 ';' / 'run;' ;
run;

proc datasets nolist lib=mylib;
%include code / source2;
quit;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1780 views
  • 0 likes
  • 2 in conversation