BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DiG
Fluorite | Level 6 DiG
Fluorite | Level 6

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.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

2 REPLIES 2
ballardw
Super User

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.

DiG
Fluorite | Level 6 DiG
Fluorite | Level 6

Yes, it works! Thanks a lot !!

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 3005 views
  • 0 likes
  • 2 in conversation