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.

494 DO IF<br />

Logical Expressions<br />

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

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

operators. Logical expressions can use any of the numeric or string functions allowed in<br />

COMPUTE transformations (see COMPUTE).<br />

• Parentheses can be used to enclose the logical expression itself and to specify the order<br />

of operations within a logical expression. Extra blanks or parentheses can be used to make<br />

the expression easier to read.<br />

• Blanks (not commas) are used to separate relational operators from expressions.<br />

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

Relations cannot be abbreviated. For example, the first relation below is valid; the second<br />

is not:<br />

Valid: (A EQ 2 OR A EQ 5)<br />

Not valid: (A EQ 2 OR 5)<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 a logical function (SYSMIS, MISSING, ANY, or<br />

RANGE) to a number.<br />

Operations<br />

• DO IF marks the beginning of the control structure and END IF marks the end. Control for<br />

a case is passed out of the structure as soon as a logical condition is met on a DO IF, ELSE<br />

IF, or ELSE command.<br />

• A logical expression is evaluated as true, false, or missing. A transformation specified for<br />

a logical expression is executed only if the expression is true.<br />

• Logical expressions are evaluated in the following order: functions, exponentiation, arithmetic<br />

operations, relations, and finally, logical operators. (For strings, the order is functions,<br />

relations, and then logical operators.) When more than one logical operator is used,<br />

NOT is evaluated first, followed by AND and then OR. You can change the order of operations<br />

using parentheses.<br />

• Numeric variables created within a DO IF structure are initially set to the system-missing<br />

value. By default, they are assigned an F8.2 format.<br />

• New string variables created within a DO IF structure are initially set to a blank value and<br />

are assigned the format specified on the STRING command that creates them.<br />

• If the transformed value of a string variable exceeds the variable’s defined format, the<br />

value is truncated. If the value is shorter than the format, the value is right-padded with<br />

blanks.<br />

• If WEIGHT is specified within a DO IF structure, it takes effect unconditionally.<br />

• <strong>Command</strong>s like SET, DISPLAY, SHOW, and so forth specified within a DO IF structure are<br />

executed when they are encountered in the command file.<br />

• The DO IF—END IF structure (like LOOP—END LOOP) can include commands such as<br />

DATA LIST, END CASE, END FILE, and REREAD, which define complex file structures.

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

Saved successfully!

Ooh no, something went wrong!