⇤ ← Revision 1 as of 2021-09-09 14:52:30
Size: 1468
Comment:
|
Size: 1536
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 2: | Line 2: |
[[SPSS]] macros are fundamentally a form of string manipulation. |
SPSS Macros
SPSS macros are fundamentally a form of string manipulation.
Arguments
Arguments can be passed into a macro. Be mindful that they will first be tokenized before being exposed to the macro expansion.
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 |
Named Arguments
Tokens can be set into named arguments 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
Tokens can also be set into positional indices (!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 !*.