Macro Arguments (DEFINE-!ENDDEFINE command)

The macro definition can include macro arguments, which can be assigned specific values in the macro call. There are two types of arguments: keyword and positional. Keyword arguments are assigned names in the macro definition; in the macro call, they are identified by name. Positional arguments are defined after the keyword !POSITIONAL in the macro definition; in the macro call, they are identified by their relative position within the macro definition.

  • There is no limit to the number of arguments that can be specified in a macro.
  • All arguments are specified in parentheses and must be separated by slashes.
  • If both keyword and positional arguments are defined in the same definition, the positional arguments must be defined, used in the macro body, and invoked in the macro call before the keyword arguments.

Example

* A keyword argument.
 
DEFINE macname (arg1 = !TOKENS(1))
frequencies variables = !arg1.
!ENDDEFINE.
 
macname arg1 = V1.
  • The macro definition defines macname as the macro name and arg1 as the argument. The argument arg1 has one token and can be assigned any value in the macro call.
  • The macro call expands the macname macro. The argument is identified by its name, arg1, and is assigned the value V1. V1 is substituted wherever !arg1 appears in the macro body. The macro body in this example is the FREQUENCIES command.

Example

* A positional argument.
 
DEFINE macname (!POSITIONAL !TOKENS(1)
               /!POSITIONAL !TOKENS(2))
frequencies variables = !1 !2.
!ENDDEFINE.
 
macname V1 V2 V3.
  • The macro definition defines macname as the macro name with two positional arguments. The first argument has one token and the second argument has two tokens. The tokens can be assigned any values in the macro call.
  • The macro call expands the macname macro. The arguments are identified by their positions. V1 is substituted for !1 wherever !1 appears in the macro body. V2 and V3 are substituted for !2 wherever !2 appears in the macro body. The macro body in this example is the FREQUENCIES command.