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 !!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.