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.
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
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.
Ready to level-up your skills? Choose your own adventure.