Amadeus cookies policy - you'll see this message only once.

Amadeus use cookies on this website. They help us to know a little bit about you and how you use our website, which improves the browsing experience and marketing - both for you and for others. They are stored locally on your computer or mobile device. To accept cookies, continue browsing as normal. Or, go to the privacy policy for more information.

How to Pass a Varying List of Parameters to a Macro

Ever found yourself coding something like this, where you call the same macro x number of times for a list of variables:

  %macro MyMacro(MyVar);
    ...... Perform some function against &MyVar ......
  %mend;
  %MyMacro(a);
  %MyMacro(b);
  %MyMacro(c);

Now consider this :

  %macro MyList(MyVar)/parmbuff;
    %let i = 1;
    /* Get the first Parameter */
    %let parm_&i = %scan(&syspbuff,&i,%str(%(,%))); 
    /* While current parm is not blank */
    %do %while (%str(&&parm_&i.) ne %str());
       ...... Perform some function against &&parm_&i ...... 
      %let i = %eval(&i+1); 
      /* Get next parm */
      %let parm_&i = %scan(&syspbuff,&i,%str(%(,%)));
    %end;
  %mend ;
  %MyList(a,b,c);

All we are doing in the here is calling the Macro with a varying list of parameters and then looping through that list, performing the same action against each entry. All we need do to achieve this is use the /PARMBUFF option on the macro definition, and then extract each item individually from the &SYSPBUFF macro variable.