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 (e.g. Arrays) I can use to make it more useful.
Put the control values into a dataset, or do the call execute from a cards; block:
data _null_;
input loop_val $10.;
call execute('%loopit(26062015,'!!loop_val!!',FUTSTK,30Jul2015);');
cards;
bbbbbbINFY
bbbbbbSBIN
bbbbbbbTCS
;
run;
If your parameters are in a data set look into CALL EXECUTE to call your macro.
Put the control values into a dataset, or do the call execute from a cards; block:
data _null_;
input loop_val $10.;
call execute('%loopit(26062015,'!!loop_val!!',FUTSTK,30Jul2015);');
cards;
bbbbbbINFY
bbbbbbSBIN
bbbbbbbTCS
;
run;
Thanks for your solution. It really helped. Now I have created a Dataset with the list of the scrips and using call execute to call the macro as suggested.
Why are you doing that in the first place? Datasteps are a loop, and have all the data structures and syntax necessary to perform such tasks. So simplfy your code to:
data want; set have; do i="bbbbbINFY","bbbbbSBIN","bbbbbTCS"; /* some code */ end; run;
Macro language is not a replacement for Base SAS.
%Let Macro_List=bbbbbbINFY bbbbbbSBIN bbbbbbbTCS;
%Macro Loop;
%Do i=1 %To %Sysfunc(CountW(&Macro_List.));
%Let Param=%Scan(&Macro_List.,&i.);
%loopit(26062015,&Param.,FUTSTK,30Jul2015);
%End;
%Mend;
%Loop
If your macro is mostly going to be used with the same values you can use keyword parameters to set a default value to reduce how much is entered.
Obviously I do not know your macro variable names but this should give you an idea;
%macro %loopit(D1 =26062015, str=, Var2=FUTSTK, Date=30Jul2015)
Then the call would look like
%loopit(Str=bbbbbbINFY);
The values for the other parameters would be as defined in the macro.
If you need to use a different value for one of those parameters such as date:
%loopit(Str=bbbbbbINFY, Date= 08Aug2016);
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: