BookmarkSubscribeRSS Feed
monty808
Calcite | Level 5

Hi,

I have create a macro array that I want to loop over

 

proc sql noprint;

   select distinct y

   into :depvar_list separated by  ' '

   from med.working_panel_serial_count_y;

quit;

 

depvar_list = y1 y2 y3 etc 

 

I have a macro that will execute each value 

 

%macro run_arima(dv=);

     //stuff to do

%mend run_arima;

 

 

How to I tier of the array? 

In a real language:

 

for i in depvar_list:

     run_arima(dv=i)

end

 

So how do I do that in sas ?

 

 

 

2 REPLIES 2
ballardw
Super User

Here is one example, not the only way, to build a list and loop over the elements in the list

 

%macro dummy();
Proc sql noprint;
   select distinct sex into :slist separated by ' '
   from sashelp.class
   ;
quit;

%do i = 1 %to %sysfunc(countw(&slist.));
   %let word = %scan(&slist.,&i.);

   Proc print data=sashelp.class noobs;
      where sex="&word.";
   run;
%end;
%mend;


%dummy

The function COUNTW is a data step function and for the macro language to use it must be wrapped in a %sysfunc( ) call.

 

The proc print is just a simple example of using the "word" or parameter as extracted.

 

 

Please be very careful about using phrases like

In a real language:

for i in depvar_list:
     run_arima(dv=i)
end

I know several 'real languages'. Not counting spoken languages, about 15 programming languages and dialects. SAS is just one. I might be insulted by the implication that SAS is not a "real language".

 

Reeza
Super User
This is inefficient code. You should restructure your data and use a single BY statement which means no macros at all.
https://blogs.sas.com/content/iml/2017/02/13/run-1000-regressions.html

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 2 replies
  • 991 views
  • 2 likes
  • 3 in conversation