Hi,
I have over 100 datasets in my library and need to add a uniform prefix to each of them, let's say 'bc_25'. Could you please share your knowledge how to do this?
Thanks.
One way:
proc sql;
create table work.control as
/* replace 'pre' below with your prefixe*/
select memname, catt('pre',memname) as newname
from dictionary.tables
/* replace JUNK below with your library
in capital letters
*/
where libname='JUNK'
;
quit;
data _null_;
set work.control end=lastone;
if _n_=1 then call execute('proc datasets library=junk;');
call execute ('change '||memname||'='||newname||';');
if lastone then call execute('quit;');
run;
Caution: you may have issues if the length of your prefix plus the existing name exceeds 32 characters. The generated names would not be valid and this will throw errors.
if that might happen then you need to make sure that the length of the newname is not longer than 32.
One way:
proc sql;
create table work.control as
/* replace 'pre' below with your prefixe*/
select memname, catt('pre',memname) as newname
from dictionary.tables
/* replace JUNK below with your library
in capital letters
*/
where libname='JUNK'
;
quit;
data _null_;
set work.control end=lastone;
if _n_=1 then call execute('proc datasets library=junk;');
call execute ('change '||memname||'='||newname||';');
if lastone then call execute('quit;');
run;
Caution: you may have issues if the length of your prefix plus the existing name exceeds 32 characters. The generated names would not be valid and this will throw errors.
if that might happen then you need to make sure that the length of the newname is not longer than 32.
Yes, it works! Thanks a lot ballardw !!
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.