Keyword Arguments (DEFINE-!ENDDEFINE command)

Keyword arguments are called with user-defined keywords that can be specified in any order. In the macro body, the argument name is preceded by an exclamation point. On the macro call, the argument is specified without the exclamation point.

  • Keyword argument definitions contain the argument name, an equals sign, and the !TOKENS, !ENCLOSE, !CHAREND, or !CMDEND keyword. See the topic Assigning Tokens to Arguments (DEFINE-!ENDDEFINE command) for more information.
  • Argument names are limited to 63 bytes and cannot match the character portion of a macro keyword, such as DEFINE, TOKENS, CHAREND, and so forth.
  • The keyword !POSITIONAL cannot be used in keyword argument definitions.
  • Keyword arguments do not have to be called in the order they were defined.

Example

DATA LIST FILE=MAC / V1 1-2 V2 4-5 V3 7-8.

* Macro definition.
DEFINE macdef2 (arg1 = !TOKENS(1)
               /arg2 = !TOKENS(1)
               /arg3 = !TOKENS(1))
frequencies  variables = !arg1 !arg2 !arg3.
!ENDDEFINE.

* Macro call.
macdef2 arg1=V1  arg2=V2  arg3=V3.
macdef2 arg3=V3  arg1=V1  arg2=V2.
  • Three arguments are defined: arg1, arg2, and arg3, each with one token. In the first macro call, arg1 is assigned the value V1, arg2 is assigned the value V2, and arg3 is assigned the value V3. V1, V2, and V3 are then used as the variables in the FREQUENCIES command.
  • The second macro call yields the same results as the first one. With keyword arguments, you do not need to call the arguments in the order in which they were defined.