Conditional Processing (DEFINE-!ENDDEFINE command)

The !IF construct specifies conditions for processing. The syntax is as follows:

!IF (expression) !THEN statements
                [!ELSE statements]
!IFEND
  • !IF, !THEN, and !IFEND are all required. !ELSE is optional.
  • If the result of the expression is true, the statements following !THEN are executed. If the result of the expression is false and !ELSE is specified, the statements following !ELSE are executed. Otherwise, the program continues.
  • Valid operators for the expressions include !EQ, !NE, !GT, !LT, !GE, !LE, !OR, !NOT, and !AND, or =, ~= (¬=), >, <, >=, <=, |, ~ (¬), and &.
  • When a macro is expanded, conditional processing constructs are interpreted after arguments are substituted and functions are executed.
  • !IF statements can be nested whenever necessary. Parentheses can be used to specify the order of evaluation. The default order is the same as for transformations: !NOT has precedence over !AND, which has precedence over !OR.

Example

DEFINE mymacro(type = !DEFAULT(1) !TOKENS(1))
!IF (!type = 1)!then 
frequencies variables=varone.
!ELSE 
descriptives variables=vartwo.
!IFEND
!ENDDEFINE.