Differences between revisions 2 and 3
Revision 2 as of 2023-06-14 15:27:30
Size: 1685
Comment:
Revision 3 as of 2023-06-14 15:31:19
Size: 1695
Comment:
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:

'''Arguments''' to SPSS macros need to be explicitly parsed on the macro definition.
Line 9: Line 11:
== Macro Definition ==

Arguments are passed using a macro function that is included on the macro definition itself.
== Usage ==
Line 27: Line 27:
Note that arguments are tokenized before being exposed to the macro expansion. Note that arguments are tokenized ''before'' being exposed to the macro expansion.
Line 33: Line 33:
== Named Arguments == == Usage ==



=
== Named Arguments ===
Line 56: Line 60:
== Positional Arguments == === Positional Arguments ===
Line 76: Line 80:
== Default Values == === Default Values ===

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


Default Values


CategoryRicottone

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