DATA Step, Macro, Functions and more

Check macro parameters

Reply
Occasional Contributor
Posts: 5

Check macro parameters


Hi,

I am trying to create a utility macro that would check if all the parameters defined in a macro definition are being passed by user.

%macro abc (aa= , bb=, cc=);

     ** Check macro parameters;

      %check_params;   /* this macro should check the macro parameters defined within abc macro definition are being passed by user,

                                            before actually processing futher on actual functioning of the macro */

     *--- Actual code starts here ----;

%mend abc;

%abc(aa=mm, bb=nn);

When I explored a bit, I see PARMBUFF option and SYSPBUFF system macro variable are the way out. But, this only gives me the text that was included in the invocation and not the definition. In the above example call, the user is not passing any values for parameter "cc", the SYSPBUFF will only have "(aa=mm, bb=nn)" and this is not the full set of parameters, I would like to have a check on all the defined macro parameters.

Is there any way, I can get the full set of parameters from the macro definition into a macro variable, so I can then play around and have checks on all.

Thanks very much in advance.

Satya

Contributor
Posts: 36

Re: Check macro parameters

Hi satyaG,

Why are you doing it that way, we can directly check for the value of the macro variables and exit if missing ?

Thanks,

Mike

Respected Advisor
Posts: 4,173

Re: Check macro parameters

I believe you can't retrieve the parameter definition of a macro during run-time - and this is what your utility macro would have to do.

If you don't want to re-code the same check multiple times then you could amend your utility macro in a way that it accepts a list of values which you then check.

%macro check_params(param);

     loop over the words in &param and do your checks

%mend;

%macro abc (aa= , bb=, cc=);

     ** Check macro parameters;

      %check_params(aa bb cc);  

%mend abc;

%abc(aa=mm, bb=nn);

PROC Star
Posts: 1,322

Re: Check macro parameters

Hi,

The below macro will return a list of all local macro variables that exist in the next outer scope.  So if you call it in your %abc macro before creating any other local macro variables, it will return a list of all parameters that are defined in abc.  I think %sysmexecname() and %sysmexecdepth were added in 9.3. 

%macro GetOuterScopeVars(debug=0);
 
%local MyVarList;
  proc sql noprint;
    select
     distinct(name) into :MyVarList separated by
" "
     from dictionary.macros
     where scope eq
"%sysmexecname(%eval(%sysmexecdepth - 1))";
    ;
  quit;
 
%if &debug=1 %then %put Macro vars in %str( ) %sysmexecname(%eval(%sysmexecdepth - 1)) are: &MyVarList;
%mend GetOuterScopeVars;


%macro abc (aa= , bb=, cc=);
  %
GetOuterScopeVars(debug=1)

  %
*main stuff;

%mend abc;


%abc(aa=mm, bb=nn)
Ask a Question
Discussion stats
  • 3 replies
  • 305 views
  • 0 likes
  • 4 in conversation