= SPSS Logic = SPSS supports the following '''logic structures''' for programming. <> ---- == Operators == The following logical operators are valid for logic control of SPSS commands. ||'''Operator'''|| ||`EQ` or `=` || ||`NE` or `~=` or `¬=` or `<>`|| ||`LT` or `<` || ||`LE` or `<=` || ||`GT` or `>` || ||`GE` or `>=` || ||`AND` or `&` || ||`OR` or `|` || ||`NOT` || The `OR` operator short circuits. Parentheses are used to control the order of operations between multiple relations. ---- == Conditional Processing == Use `DO IF` structures for conditional processing of SPSS commands. {{{ do if (foo = 1). compute bar = 1. else if (foo = 2). compute bar = 2. else. compute bar = 3. end if. }}} If any variable referenced in a condition is a missing value, the case falls through the structure and no commands execute for it. {{{ do if missing(foo). compute bar = 0. else if (foo = 1). compute bar = 1. else if (foo = 2). compute bar = 2. else. compute bar = 3. end if. }}} `DO IF` structures can be nested arbitrarily. === Data Model === `DO IF` structures are queued as a pending transformation. === Limitations === Any command requiring that no transformations be pending cannot be used in a `DO IF` structure. This includes most statistics and graphic commands. Any command that executes immediately and does not read the active dataset (or does not need an active dataset at all) will be executed immediately and unconditionally. This includes [[SPSS/ValueLabels|VALUE LABELS]], [[SPSS/MissingValues|MISSING VALUES]], [[SPSS/Weight|WEIGHT]], [[SPSS/Host|HOST]], and [[SPSS/Insert|INSERT]]. This is a ''limitation'' because null `DO IF` structures can be easily created. For example: {{{ do if expense=0. compute profit=-99. missing values expense (0). else/ compute profit=income - expense. end if. }}} `MISSING VALUES` executed immediately and unconditionally. When the pending transformations are eventually executed, `0` will fall through the `DO IF` structure as a user missing value. ---- CategoryRicottone