SPSS Macro Arguments
Arguments to SPSS macros need to be explicitly parsed on the macro definition.
Usage
define !foo(bar=!cmdend) compute baz=!bar. enddefine.
The available functions are:
Function |
Behavior |
!tokens(N) |
Consume N tokens |
!charend('C') |
Consume all tokens until C |
!enclose('S','E') |
Consume all tokens starting from S until E |
!cmdend |
Consume all tokens until the end of the command |
Note that arguments are tokenized before being exposed to the macro expansion.
Usage
Named Arguments
Arguments can be set into named variables using a key = function pattern.
define !generate(var1=!tokens(1) /var2=!tokens(1)) compute !var1=0. compute !var2=0. !enddefine. !generate var1=foo var2=bar. !generate var2=bar var1=foo.
Note that the arguments are accessed in the program by prepending the name with an exclamation mark (!).
Also note that arguments can be specified in any order.
Positional Arguments
Arguments can be set into positional variables (!1, !2, and so on) using the !POSITIONAL keyword.
define !generate(!positional !tokens(1) /!positional !tokens(1)) compute !1=0. compute !2=0. !enddefine. !generate foo bar.
All positional arguments can be accessed as a blank-delimited string with !*.