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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 1203 views
  • 0 likes
  • 4 in conversation