Positional Arguments (DEFINE-!ENDDEFINE command)
Positional arguments must be defined in the order
in which they will be specified on the macro call. In the macro body,
the first positional argument is referred to by !1
, the second positional argument defined is referred
to by !2
, and so on. Similarly,
the value of the first argument in the macro call is assigned to !1
, the value of the second argument is
assigned to !2
, and so on.
- Positional arguments can be collectively referred
to in the macro body by specifying
!
*. The!
* specification concatenates arguments, separating individual arguments with a blank.
Example
DATA LIST FILE='/data/mac.txt' / V1 1-2 V2 4-5 V3 7-8.
* Macro definition.
DEFINE macdef (!POS !TOKENS(1)
/!POS !TOKENS(1)
/!POS !TOKENS(1))
frequencies variables = !1 !2 !3.
!ENDDEFINE.
* Macro call.
macdef V1 V2 V3.
macdef V3 V1 V2.
- Three positional arguments with one token each are
defined. The first positional argument is referred to by
!1
on theFREQUENCIES
command, the second by!2
, and the third by!3
. - When the first call expands the macro, the first
positional argument (
!1
) is assigned the valueV1
, the second positional argument (!2
) is assigned the valueV2
, and the third positional argument (!3
) is assigned the valueV3
. - In the second call, the first positional argument
is assigned the value
V3
, the second positional argument is assigned the valueV1
, and the third positional argument is assigned the valueV2
.
Example
DEFINE macdef (!POS !TOKENS(3))
frequencies variables = !1.
!ENDDEFINE.
macdef V1 V2 V3.
- This example is the same as the previous one, except that it assigns three tokens to one argument instead of assigning one token to each of three arguments. The result is the same.
Example
DEFINE macdef (!POS !TOKENS(1)
/!POS !TOKENS(1)
/!POS !TOKENS(1)
frequencies variables = !*.
!ENDDEFINE.
macdef V1 V2 V3.
- This is a third alternative for achieving the macro
expansion shown in the previous two examples. It specifies three arguments
but then joins them all together on one
FREQUENCIES
command using the symbol!
*.