简体   繁体   中英

How to use loops for macro function calls in sas

I am using the following statements for function calls in sas

%loopit(26062015,bbbbbbINFY,FUTSTK,30Jul2015);
%loopit(26062015,bbbbbbSBIN,FUTSTK,30Jul2015);
%loopit(26062015,bbbbbbbTCS,FUTSTK,30Jul2015);

where i have already have defined the loopit macro previously in the code. As it can be seen, in the function calls, only one parameter changes while the rest are same. I wanted to if there are any loop structures (eg Arrays) I can use to make it more useful.

You can define a list of parameters to loop through and then call %loopit on each of them:

%let param_list = bbbbbbINFY bbbbbbSBIN bbbbbbbTCS;

%macro loop_them;

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

        %loopit(26062015,&this_param.,FUTSTK,30Jul2015);

    %end;

%mend loop_them;

%loop_them;

You can use the call execute function. For example if you have a sequential count base parameter you are passing then you can use the following code:

Data _NULL_;
count = 0;
for i=0 to 10;
call execute ( ‘%loopit(count)’ );
end;
run;

I am not entirely sure about the syntax used above. Google for more clarity. I have used call execute in the same manner earlier.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM