Reputation: 85
Is there a way to the rename the same variables in multiple tables in ONE SAS library, where there are also other tables that do not have that table? All of the tables that have variables that need renamed have the same two characters that start the table name. I've seen macros to rename multiple variables in one dataset but not to rename multiple variables in multiple datasets. Any help as to if this is possible would be appreciated!
Upvotes: 0
Views: 658
Reputation: 9569
No need for macros. You could pull something together using call execute and proc datasets. E.g.
data _null_;
set sashelp.vtable end = eof;
/*Replace xx with your two-letter dataset prefix*/
where libname = upcase('mylib') and memname eq: upcase('xx') and memtype = 'DATA';
if _n_ = 1 then call execute('proc datasets lib = mylib;');
call execute(catx(' ','modify',memname,'; rename var1 = newvar1 var2 = newvar2; run;'));
if eof then call execute('quit;');
run;
This should run more or less instantaneously as it only needs to modify the metadata.
Upvotes: 1