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 ?
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".
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
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.
Ready to level-up your skills? Choose your own adventure.