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.

Overview<br />

DO IF 493<br />

The DO IF—END IF structure conditionally executes one or more transformations on subsets<br />

of cases based on one or more logical expressions. The ELSE command can be used within<br />

the structure to execute one or more transformations when the logical expression on DO IF<br />

is not true. The ELSE IF command within the structure provides further control.<br />

The DO IF—END IF structure is best used for conditionally executing multiple transformation<br />

commands, such as COMPUTE, RECODE, and COUNT. IF is more efficient for<br />

executing a single conditional COMPUTE-like transformation. DO IF—END IF transforms<br />

data for subsets of cases defined by logical expressions. To perform repeated transformations<br />

on the same case, use LOOP—END LOOP.<br />

A DO IF—END IF structure can be used within an input program to define complex files<br />

that cannot be handled by standard file definition facilities. See “Complex File Structures”<br />

on p. 499 for an example.<br />

See END FILE for information on using DO IF—END IF to instruct the program to stop<br />

reading data before it encounters the end of the file or to signal the end of the file when<br />

creating data. See p. 422 for an example of using DO IF—END IF with END FILE to concatenate<br />

raw data files.<br />

Basic Specification<br />

The basic specification is DO IF followed by a logical expression, a transformation command,<br />

and the END IF command, which has no specifications.<br />

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

• The ELSE IF command is optional and can be repeated as many times as needed.<br />

• The ELSE command is optional. It can be used only once and must follow any ELSE IF<br />

commands.<br />

• The END IF command must follow any ELSE IF and ELSE commands.<br />

• A logical expression must be specified on the DO IF and ELSE IF commands. Logical<br />

expressions are not used on the ELSE and END IF commands.<br />

• String values used in expressions must be specified in quotation marks and must include<br />

any leading or trailing blanks. Lowercase letters are distinguished from uppercase letters.<br />

• To create a new string variable within a DO IF—END IF structure, you must first declare<br />

the variable on the STRING command.<br />

• DO IF—END IF structures can be nested to any level permitted by available memory. They<br />

can be nested within LOOP—END LOOP structures, and loop structures can be nested<br />

within DO IF structures.

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

Saved successfully!

Ooh no, something went wrong!