BookmarkSubscribeRSS Feed
shivakrishna
Fluorite | Level 6

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

2 REPLIES 2
jakarman
Barite | Level 11

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 --<-----
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 529 views
  • 0 likes
  • 3 in conversation