Overview (SELECT IF command)
SELECT IF
permanently
selects cases for analysis based on logical conditions that are found in the
data. These conditions are specified in a logical
expression. The logical expression can contain relational operators,
logical operators, arithmetic operations, and any functions that are allowed
in COMPUTE
transformations. For temporary
case selection, specify a TEMPORARY
command
before SELECT IF
.
Basic Specification
The basic specification is simply a logical expression.
Syntax Rules
- Logical expressions can be simple logical variables or relations,
or these expressions can be complex logical tests involving variables, constants,
functions, relational operators, and logical operators. The logical expression
can use any of the numeric or string functions that are allowed in
COMPUTE
transformations (seeCOMPUTE
and see Transformation Expressions ). - Parentheses can be used to enclose the logical expression. Parentheses can also be used within the logical expression to specify the order of operations. Extra blanks or parentheses can be used to make the expression easier to read.
- A relation can compare variables, constants, or more complicated
arithmetic expressions. Relations cannot be abbreviated. For example,
(A EQ 2 OR A EQ 5)
is valid while(A EQ 2 OR 5)
is not valid. Blanks (not commas) must be used to separate relational operators from the expressions that are being compared. - A relation cannot compare a string variable to a numeric value
or variable, or vice versa. A relation cannot compare the result of the logical
functions
SYSMIS
,MISSING
,ANY
, orRANGE
to a number. - String values that are used in expressions must be specified in quotation marks and must include any leading or trailing blanks. Lowercase letters are considered distinct from uppercase letters.
Operations
-
SELECT IF
permanently selects cases. Cases that are not selected are dropped from the active dataset. - The logical expression is evaluated as true, false, or missing. If a logical expression is true, the case is selected; if it is false or missing, the case is not selected.
- Multiple
SELECT IF
commands that are issued prior to a procedure command must all be true for a case to be selected. -
SELECT IF
should be placed before other transformations for efficiency. - Logical expressions are evaluated in the following order: numeric functions, exponentiation, arithmetic operators, relational operators, and logical operators. Use parentheses to change the order of evaluation.
- If
N OF CASES
is used withSELECT IF
, the program reads as many records as required to build the specified n cases. It makes no difference whetherN OF CASES
precedes or followsSELECT IF
. - System
variable
$CASENUM
is the sequence number of a case in the active dataset. Although it is syntactically correct to use$CASENUM
onSELECT IF
, it does not produce the expected results. To select a set of cases based on their sequence in a file, create your own sequence variable with the transformation language prior to making the selection (see the Examples) .
Missing Values
- If the logical expression is indeterminate because of missing values, the case is not selected. In a simple relational expression, a logical expression is indeterminate if the expression on either side of the relational operator is missing.
- If a compound expression is used
in which relations are joined by the logical operator
OR
, the case is selected if either relation is true, even if the other relation is missing. - To select cases with missing values for the
variables within the expression, use the missing-value functions. To include
cases with values that have been declared user-missing, along with other cases,
use the
VALUE
function.
Limitations
SELECT IF
cannot be
placed within a FILE TYPE-END FILE TYPE
or INPUT PROGRAM-END INPUT PROGRAM
structure. SELECT IF
can be placed nearly anywhere following
these commands in a transformation program. See the topic Commands and Program States for more information.