27.03.2013 Views

SPSS® 12.0 Command Syntax Reference

SPSS® 12.0 Command Syntax Reference

SPSS® 12.0 Command Syntax Reference

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Basic Specification<br />

IF 737<br />

The basic specification is a logical expression followed by a target variable, a required<br />

equals sign, and the assignment expression. The assignment is executed only if the logical<br />

expression is true.<br />

<strong>Syntax</strong> Rules<br />

• Logical expressions can be simple logical variables or relations, or complex logical tests<br />

involving variables, constants, functions, relational operators, and logical operators. Both<br />

the logical expression and the assignment expression can use any of the numeric or string<br />

functions allowed in COMPUTE transformations (see COMPUTE and “Transformation<br />

Expressions” on p. 37).<br />

• Parentheses can be used to enclose the logical expression. Parentheses can also be used<br />

within the logical expression to specify the order of operations. Extra blanks or parentheses<br />

can be used to make the expression easier to read.<br />

• A relation can compare variables, constants, or more complicated arithmetic expressions.<br />

Relations cannot be abbreviated. For example, (A EQ 2 OR A EQ 5) is valid, while<br />

(A EQ 2 OR 5) is not. Blanks (not commas) must be used to separate relational operators<br />

from the expressions being compared.<br />

• A relation cannot compare a string variable to a numeric value or variable, or vice versa.<br />

A relation cannot compare the result of the logical functions SYSMIS, MISSING, ANY, or<br />

RANGE to a number.<br />

• String values used in expressions must be specified in quotes and must include any leading<br />

or trailing blanks. Lowercase letters are considered distinct from uppercase letters.<br />

• String variables that are used as target variables must already exist. To declare a new<br />

string variable, first create the variable with the STRING command and then specify the<br />

new variable as the target variable on IF.<br />

Operations<br />

• Each IF command evaluates every case in the data. Compare IF with DO IF, which passes<br />

control for a case out of the DO IF—END IF structure as soon as a logical condition is met.<br />

• The logical expression is evaluated as true, false, or missing. The assignment is executed<br />

only if the logical expression is true. If the logical expression is false or missing, the<br />

assignment is not made. Existing target variables remain unchanged; new numeric variables<br />

retain their initial (system-missing) values.<br />

• In general, a logical expression is evaluated as missing if any one of the variables used<br />

in the logical expression is system- or user-missing. However, when relations are joined<br />

by the logical operators AND or OR, the expression can sometimes be evaluated as true<br />

or false even when variables have missing values (see “Missing Values and Logical<br />

Operators” on p. 738).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!