BookmarkSubscribeRSS Feed
SatyaG
Calcite | Level 5


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

3 REPLIES 3
Micheal_S
Calcite | Level 5

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

Patrick
Opal | Level 21

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

Quentin
Super User

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)
BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1209 views
  • 0 likes
  • 4 in conversation