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.

MATRIX—END MATRIX 939<br />

• The DO IF statement marks the beginning of the structure, and the END IF statement marks<br />

its end.<br />

• The ELSE IF statement is optional and can be repeated as many times as desired within the<br />

structure.<br />

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

• The END IF statement must follow any ELSE IF and ELSE statements.<br />

• The DO IF and ELSE IF statements must contain a logical expression, normally one<br />

involving the relational operators EQ, GT, and so on. However, the matrix language allows<br />

any expression that evaluates to a scalar to be used as the logical expression. Scalars greater<br />

than 0 are considered true, and scalars less than or equal to 0 are considered false.<br />

A DO IF structure affects the flow of control within a matrix program as follows:<br />

• If the logical expression on the DO IF statement is true, the statements immediately<br />

following the DO IF are executed up to the next ELSE IF or ELSE in the structure. Control<br />

then passes to the first statement following the END IF for that structure.<br />

• If the expression on the DO IF statement is false, control passes to the first ELSE IF, where<br />

the logical expression is evaluated. If this expression is true, statements following the ELSE<br />

IF are executed up to the next ELSE IF or ELSE statement, and control passes to the first<br />

statement following the END IF for that structure.<br />

• If the expressions on the DO IF and the first ELSE IF statements are both false, control passes<br />

to the next ELSE IF, where that logical expression is evaluated. If none of the expressions is<br />

true on any of the ELSE IF statements, statements following the ELSE statement are executed<br />

up to the END IF statement, and control falls out of the structure.<br />

• If none of the expressions on the DO IF statement or the ELSE IF statements is true and there<br />

is no ELSE statement, control passes to the first statement following the END IF for that<br />

structure.<br />

LOOP Structures<br />

A LOOP structure in a matrix program affects the flow of control exactly as the analogous<br />

commands affect an SPSS transformation program, except that missing-value considerations<br />

do not arise in a matrix program. Its syntax is as follows:<br />

LOOP [varname=n TO m [BY k]] [IF [(]logical expression[)]<br />

matrix statements<br />

[BREAK]<br />

matrix statements<br />

END LOOP [IF [(]logical expression[)]]<br />

The matrix statements specified between LOOP and END LOOP are executed repeatedly until<br />

one of the following four conditions is met:<br />

• A logical expression on the IF clause of the LOOP statement is evaluated as false.<br />

• An index variable used on the LOOP statement passes beyond its terminal value.

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

Saved successfully!

Ooh no, something went wrong!