SPSS Macro 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. Additional conditions can be expressed with !IF !ELSE or !ELSE.
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
!enddefineInside the !IF construct, string literals can be left unquoted. This comes with the unexpected side-effect of case-sensitivity.
