BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Anirban
Obsidian | Level 7

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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;

View solution in original post

6 REPLIES 6
Reeza
Super User

If your parameters are in a data set look into CALL EXECUTE to call your macro.  

Kurt_Bremser
Super User

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;
Anirban
Obsidian | Level 7

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

user24feb
Barite | Level 11
%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
ballardw
Super User

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);

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 6 replies
  • 2010 views
  • 4 likes
  • 6 in conversation