SPSS Macro Logic

SPSS macros offer the following options for logic.


Operators

The following logical operators are valid for logic control of SPSS macros.

Operator

!EQ, =

!NE, ~=

!GT, >

!GE, >=

!LT, <

!LE, <=

!OR, |

!AND, &

!NOT, ~


Conditional Processing

The !IF ... !THEN ... !IFEND syntax is used for conditional processing inside a macro. !ELSE is optional. Further logic can be expressed in nested blocks.

define !export(type = !tokens(1))
  !IF (!type !EQ "xlsx") !THEN
    save translate /outfile="export.xlsx" /type=xlsx /version=12 /map /replace /fieldnames /cells=values.
  !ELSE
    !IF (!type !EQ "dta") !THEN
      save translate /outfile="export.dta" /type=stata /version=8 /edition=se /map /replace.
    !ELSE
      save outfile="export.sav".
    !IFEND
  !IFEND
!enddefine

Inside the !IF construct, string literals can be left unquoted. This comes with the unexpected side-effect of case-sensitivity.


CategoryRicottone

SPSS/Macro/Logic (last edited 2024-10-01 21:36:35 by DominicRicottone)