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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Transformation Expressions 49<br />

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

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

operators, and parentheses to control the order of evaluation.<br />

• On an IF command, a logical expression that is true causes the assignment expression to<br />

be executed. A logical expression that returns missing has the same effect as one that is<br />

false: the assignment expression is not executed and the value of the target variable is not<br />

altered.<br />

• On a DO IF command, a logical expression that is true causes SPSS to execute the<br />

commands immediately following the DO IF, up to the next ELSE IF, ELSE, or END IF. If<br />

it is false, SPSS looks for the next ELSE IF or ELSE command. If the logical expression<br />

returns missing for each of these, the entire structure is skipped.<br />

• On a SELECT IF command, a logical expression that is true causes the case to be selected.<br />

A logical expression that returns missing has the same effect as one that is false: the case<br />

is not selected.<br />

• On a LOOP IF command, a logical expression that is true causes looping to begin (or<br />

continue). A logical expression that returns missing has the same effect as one that is<br />

false: the structure is skipped.<br />

• On an END LOOP IF command, a logical expression that is false returns control to the<br />

LOOP command for that structure and looping continues. If it is true, looping stops and<br />

the structure is terminated. A logical expression that returns a missing value has the same<br />

effect as one that is true: the structure is terminated.<br />

String Variables in Logical Expressions<br />

String variables, like numeric variables, can be tested in logical expressions.<br />

• String variables must be declared before they can be used in a string expression.<br />

• String variables cannot be compared to numeric variables.<br />

• If strings of different lengths are compared, the shorter string is right-padded with blanks<br />

to equal the length of the longer.<br />

• The magnitude of strings can be compared using LT, GT, and so on, but the outcome<br />

depends on the sorting sequence of the computer. Use with caution.<br />

Logical Functions<br />

• Each argument to a logical function (expression, variable name, or constant) must be<br />

separated by a comma.<br />

• The target variable for a logical function must be numeric.<br />

• The functions RANGE and ANY can be useful shortcuts to more complicated specifications<br />

on the IF, DO IF, and other conditional commands. For example, the command<br />

SELECT IF ANY(REGION,’NW’,’NE’,’SE’).<br />

is equivalent to<br />

SELECT IF (REGION EQ ’NW’ OR REGION EQ ’NE’ OR REGION EQ<br />

’SE’).

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

Saved successfully!

Ooh no, something went wrong!