In which criteria we have to use positional and keyword parameters in macro

Reply
Contributor
Posts: 56

In which criteria we have to use positional and keyword parameters in macro

Hi All,

Could you please anyone explain in which situation we have to use which parameter like key and positional parameters.

Is there any particular situation for using those parameters.

Thanks

Shiva

Trusted Advisor
Posts: 3,212

Re: In which criteria we have to use positional and keyword parameters in macro

Posted in reply to shivakrishna

That is the macro designers job to decide.  To help, the parameter approach is easier with setting default values. SAS(R) 9.3 Macro Language: Reference (%macro)

---->-- ja karman --<-----
Super User
Super User
Posts: 7,942

Re: In which criteria we have to use positional and keyword parameters in macro

Posted in reply to shivakrishna

I would use named parameters as much as possible.  They are easier to document, make the code easier to read.  For instance if you optional parameters you could have either:

%macro do_something (avar,avar2,,,,,,some_new_var,,,,);

Or

%macro do_something (variable_to_process=avar,

                                        variable_label=avar2,

                                        output_variable=some_new_var);

This is however an opinion, and there are some occasions where it doesn't help any to have named parameters, for instance where macros are embedded in other macros:

%macro big_loop (loop_start=,loop_end=,var=);

     %macro inner_loop (a,b);

          do loop over a to b;

     %mend inner_loop;

     %inner_loop(loop_start,loop_end;

%mend big_loop;    

As the user never sees the inner loop macro, then it really doesn't need documenting.  So, if another person has to use it, maybe veer towards named paramers.

Ask a Question
Discussion stats
  • 2 replies
  • 171 views
  • 0 likes
  • 3 in conversation