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

I have 66 datasets namely, Plan_1, Plan_2 ....... , Plan_66

I want to rename them to -- _2013_010_plan_sas, _2013_020_plan_sas, etc...there is no sequential order to these numbers, so I put them in an array,

array names{*} _2013_010_Plan_SAS

_2013_020_Plan_SAS

_2013_265_Plan_SAS

_2013_332_Plan_SAS .......;

But how do I use this array to rename the datasets via a macro, maybe.............or if there is any other way, please let me know.

Thanks, in advance!!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You need to generate code but a macro is not needed.

It will be easy read the new names as input DATA can generate the corresponding old name based on the location in the list.

data renames ;

   input newname $32. ;

   n+1;

   oldname = catx('_','plan',n);

cards;

_2013_010_Plan_SAS

_2013_020_Plan_SAS

...

run;

proc sql noprint ;

  select catx('=',oldname,newname) into :renames separated by ' '

  from renames

  ;

quit;

proc datasets nolist lib=work;

change &renames ;

run; quit;

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

You need to generate code but a macro is not needed.

It will be easy read the new names as input DATA can generate the corresponding old name based on the location in the list.

data renames ;

   input newname $32. ;

   n+1;

   oldname = catx('_','plan',n);

cards;

_2013_010_Plan_SAS

_2013_020_Plan_SAS

...

run;

proc sql noprint ;

  select catx('=',oldname,newname) into :renames separated by ' '

  from renames

  ;

quit;

proc datasets nolist lib=work;

change &renames ;

run; quit;

Xinxin
Obsidian | Level 7

Thank you...it worked !!

sas-innovate-2024.png

Today is the last day to save with the early bird rate! Register today for just $695 - $100 off the standard rate.

 

Plus, pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 412 views
  • 0 likes
  • 2 in conversation