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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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