BookmarkSubscribeRSS Feed
Helfy
Calcite | Level 5
Apologies if this has been discussed before, I couldn't find a solution through a search.

I want to create a single data step framework that runs inside a macro loop driven by an array of string variables...

As simply as I can put it...

Say I have the array, days{7} sun mon tue wed thu fri sat;

I want to loop a single data step using this array to generate...

data sun; (each new dataset gets its name from the array variable)
set old;
keep var1 var2;
day = sun; (array variable can be used inside data step as well)
run;

data mon;
set old;
keep var1 var2;
day = mon;
run;

...and so on through the entire list of strings. Is this possible? I've been trying to use %DO_OVER but I can't seem to get the format right. Also SCAN has been another dry run. Is it just the case that the macro language does not support arrays, and I should just create separate data steps?

Thanks for any help or advice.
4 REPLIES 4
CurtisMack
Fluorite | Level 6
I am not clear what form your "array" is in. Is is inside a dataset, or do you have a delimited list, or somthing else?
Reeza
Super User
I think you need to look at processing data with a macro variable LIST rather than array.

See this paper:
http://www2.sas.com/proceedings/sugi30/028-30.pdf

HTH,
Reeza
Reeza
Super User
I think you need to look at processing data with a macro variable LIST rather than array.

See this paper:
http://www2.sas.com/proceedings/sugi30/028-30.pdf

HTH,
Reeza
Ksharp
Super User
Hi.
It looks like you want to split dataset?



%macro split;



proc sql ;



 select distinct sex from sashelp.class;



 select distinct sex



   into : sex1 - : sex&sqlobs.



    from sashelp.class;



quit;



data %do i=1 %to &sqlobs.;



       &&sex&i



    
%end;



    
;



 set sashelp.class;



 select (sex);



  %do j=1 %to
&
sqlobs.;



   when("&&sex&j") output &&sex&j;



  %end;



  otherwise;



 end;



run;



%mend;



 



%split









[pre]


Ksharp
[/pre]

Message was edited by: Ksharp

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1573 views
  • 0 likes
  • 4 in conversation