Size: 1907
Comment:
|
Size: 2228
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 66: | Line 66: |
=== Data Model === `DO IF` structures are queued as a pending transformation. |
|
Line 68: | Line 74: |
Any command that requires an immediate data pass cannot be used in a `DO IF` structure. This includes most statistics and graphic commands. | Any command requiring that no transformations be pending cannot be used in a `DO IF` structure. This includes most statistics and graphic commands. |
Line 70: | Line 76: |
Any command that takes effect immediately and does not read data will be executed unconditionally. This includes [[SPSS/ValueLabels|VALUE LABELS]], [[SPSS/MissingValues|MISSING VALUES]], [[SPSS/VariableLabel|VARIABLE LABEL]], and [[SPSS/Weight|WEIGHT]]. | 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, unconditionally, and repeated in every loop. 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: |
Line 72: | Line 78: |
Any command that does not require an active dataset will be executed unconditionally. This includes [[SPSS/Display|DISPLAY]], [[SPSS/Host|HOST]], [[SPSS/Insert|INSERT]], [[SPSS/OutputManagementSystem|OMS]], and [[SPSS/Set|SET]]. | {{{ do if expense=0. compute profit=-99. missing values expense (0). else/ compute profit=income - expense. end if. }}} |
Line 74: | Line 87: |
The [[SPSS/Get|GET]] command is executed unconditionally. | `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. |
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, unconditionally, and repeated in every loop. This includes VALUE LABELS, MISSING VALUES, WEIGHT, HOST, and 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.