Differences between revisions 1 and 2
Revision 1 as of 2023-01-13 20:55:24
Size: 1687
Comment:
Revision 2 as of 2023-06-14 15:27:30
Size: 1685
Comment:
Deletions are marked like this. Additions are marked like this.
Line 14: Line 14:
define !foo(bar=!cmdend()) define !foo(bar=!cmdend)
Line 22: Line 22:
||`!tokens(N)` ||Consume N tokens ||
||`!charend('C')` ||Consume all tokens until C ||
||`!enclose('S','E')`||Consume all tokens starting from S until E     ||
||`!tokens(N)` ||Consume `N` tokens ||
||`!charend('C')` ||Consume all tokens until `C` ||
||`!enclose('S','E')`||Consume all tokens starting from `S` until `E` ||

SPSS Macro Arguments


Macro Definition

Arguments are passed using a macro function that is included on the macro definition itself.

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.


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 !*.


Default Values


CategoryRicottone

SPSS/Macro/Arguments (last edited 2023-06-14 15:42:38 by DominicRicottone)