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-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

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

Browse our catalog!

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