8 users online | 8 Guests and 0 Registered

When is a positional parameter not a positional parameter?


Macro Program definitions allow for both positional and keyword parameters.  Positional paramater values must be specified on the Macro Program call in the order in which they were listed on the definition.  Keyword parameters can be specified in any order, or omitted and will assume default values as given on the definition.

A parameter which has been defined as Positional may however also be called as Keyword.

Consider the code:

%macro params(pos1,key1 = ,key2 = ) ;
  %if &pos1 = ? or %upcase(&pos1) = HELP %then
  %do ;
    %put NOTE: The first parameter can be used to identify which parameters are expected. ;
    %put NOTE- This macro has three parameters: ;
    %put NOTE-   pos1 - which may be submitted as either positional or keyword. ;
    %put NOTE-   key1 - which is a keyword parameter. ;
    %put NOTE-   key2 - which is a keyword parameter. ;
  %end ;
  %put NOTE: This macro ran successfully. ;
%mend params ;

The definition has one Positional and two Keyword parameters.

Submitting the Macro Program calls:

%params(pos1 = ?)

%params(HELP)

Generates the LOG:

13   %params(pos1 = ?)
NOTE: The first parameter can be used to identify which parameters are expected.
      This macro has three parameters:
        pos1 - which may be submitted as either positional or keyword.
        key1 - which is a keyword parameter.
        key2 - which is a keyword parameter.
NOTE: This macro ran successfully.
14
15   %params(HELP)
NOTE: The first parameter can be used to identify which parameters are expected.
      This macro has three parameters:
        pos1 - which may be submitted as either positional or keyword.
        key1 - which is a keyword parameter.
        key2 - which is a keyword parameter.
NOTE: This macro ran successfully.

from which it can be seen that pos1 may be called using eiher form.

Tags: keyword, positional
Author:
Alan D Rudland
Revision:
1.4
Average rating:0 (0 Votes)

You cannot comment on this entry

Chuck Norris has counted to infinity. Twice.