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;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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
  • 1884 views
  • 0 likes
  • 2 in conversation