Differences between revisions 2 and 8 (spanning 6 versions)
Revision 2 as of 2021-09-09 14:53:26
Size: 1536
Comment:
Revision 8 as of 2023-06-14 15:29:09
Size: 583
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
= SPSS Macros = = SPSS Macro Language =
Line 3: Line 3:
[[SPSS]] macros are fundamentally a form of string manipulation. The '''SPSS macro language''' is a string manipulation and expansion facility.
Line 11: Line 11:
== Arguments == == Example ==
Line 13: Line 13:
Arguments can be passed into a macro. Be mindful that they will first be tokenized before being exposed to the macro expansion. {{{
define !HelloWorld()
  string HelloWorld (A13).
  compute HelloWorld="Hello, World!".
  list HelloWorld.
enddefine.
}}}
Line 15: Line 21:
||'''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||
----
Line 23: Line 25:
=== Named Arguments === == Language ==
Line 25: Line 27:
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 `!*`.
 * [[SPSS/Macro/Arguments|Macro Arguments]]
 * [[SPSS/Macro/Arithmetic|Macro Arithmetic]]
 * [[SPSS/Macro/Logic|Macro Logic]]
 * [[SPSS/Macro/Looping|Macro Looping]]
 * [[SPSS/Macro/StringFunctions|Macro String Functions]]

SPSS Macro Language

The SPSS macro language is a string manipulation and expansion facility.


Example

define !HelloWorld()
  string HelloWorld (A13).
  compute HelloWorld="Hello, World!".
  list HelloWorld.
enddefine.


Language


CategoryRicottone

SPSS/Macro (last edited 2023-06-14 15:29:09 by DominicRicottone)