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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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