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.

IF<br />

IF [(]logical expression[)] target variable=expression<br />

The following relational operators can be used in logical expressions:<br />

Symbol Definition Symbol Definition<br />

EQ or = Equal to NE or * Not equal to<br />

LT or < Less than LE or Greater than GE or >= Greater than or equal to<br />

* On ASCII systems (for example, UNIX, VAX, and all PC’s) you can also use ~=;<br />

on IBM EBCDIC systems (for example, IBM 360 and IBM 370) you can also use ¬=.<br />

The following logical operators can be used in logical expressions:<br />

Symbol Definition<br />

AND or & Both relations must be true<br />

Or or | Either relation can be true<br />

Not* Reverses the outcome of an expression *<br />

* On ASCII systems you can also use ~; on IBM EBCDIC systems<br />

you can also use ¬ (or the symbol above number 6).<br />

Example<br />

Overview<br />

IF (AGE > 20 AND SEX = 1) GROUP=2.<br />

IF conditionally executes a single transformation command based upon logical conditions<br />

found in the data. The transformation can create a new variable or modify the values of an<br />

existing variable for each case in the working data file. You can create or modify the values<br />

of both numeric and string variables. If you create a new string variable, you must first declare<br />

it on the STRING command.<br />

IF has three components: a logical expression (see “Logical Expressions” on p. 48) that<br />

sets up the logical criteria, a target variable (the one to be modified or created), and an<br />

assignment expression. The target variable’s values are modified according to the assignment<br />

expression.<br />

IF is most efficient when used to execute a single, conditional, COMPUTE-like transformation.<br />

If you need multiple IF statements to define the condition, it is usually more efficient<br />

to use the RECODE command or a DO IF—END IF structure.<br />

736

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

Saved successfully!

Ooh no, something went wrong!