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 !!
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.