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.

838 LOOP—END LOOP<br />

Example<br />

LOOP #I=1 TO Z IF (Y GT 10). /*Loop to X=Z for cases with Y GT 10<br />

COMPUTE X=X+1.<br />

END LOOP.<br />

• The value of X remains unchanged for cases with a missing value for Y or a missing value<br />

for Z (or if Z is less than 1).<br />

Example<br />

MISSING VALUES X(5).<br />

LOOP.<br />

COMPUTE X=X+1.<br />

END LOOP IF (X GE 10). /*Loop until X is at least 10 or missing<br />

• Looping is terminated when the value of X is 5 because 5 is defined as missing for X.<br />

Example<br />

LOOP IF NOT MISSING(Y). /*Loop only when Y isn’t missing<br />

COMPUTE X=X+Y.<br />

END LOOP IF (X GE 10). /*Loop until X is at least 10<br />

• The variable X is unchanged for cases with a missing value for Y, since the loop is never<br />

entered.<br />

Creating Data<br />

A loop structure and an END CASE command within an input program can be used to create<br />

data without any data input. The END FILE command must be used outside the loop (but<br />

within the input program) to terminate processing.<br />

Example<br />

INPUT PROGRAM.<br />

LOOP #I=1 TO 20.<br />

COMPUTE AMOUNT=RND(UNIFORM(5000))/100.<br />

END CASE.<br />

END LOOP.<br />

END FILE.<br />

END INPUT PROGRAM.<br />

PRINT FORMATS AMOUNT (DOLLAR6.2).<br />

PRINT /AMOUNT.<br />

EXECUTE.<br />

• This example creates 20 cases with a single variable, AMOUNT. AMOUNT is a uniformly<br />

distributed number between 0 and 5000, rounded to an integer and divided by 100 to<br />

provide a variable in dollars and cents.<br />

• The END FILE command is required to terminate processing once the loop structure is<br />

complete.<br />

See pp. 503 and 512 for other examples of creating data without any data input.

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

Saved successfully!

Ooh no, something went wrong!