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.

LOOP—END LOOP 837<br />

• The loop is executed once for a case with Y equal to 2 and Z equal to 2 but twice for a case<br />

with Y equal to 3 and Z equal to 2.<br />

Example<br />

* Repeating data using LOOP.<br />

INPUT PROGRAM.<br />

DATA LIST NOTABLE/ ORDER 1-4(N) #BKINFO 6-71(A).<br />

LEAVE ORDER.<br />

LOOP #I = 1 TO 66 BY 6 IF SUBSTR(#BKINFO,#I,6) ’ ’.<br />

+ REREAD COLUMN = #I+5.<br />

+ DATA LIST NOTABLE/ ISBN 1-3(N) QUANTITY 4-5.<br />

+ END CASE.<br />

END LOOP.<br />

END INPUT PROGRAM.<br />

SORT CASES BY ISBN ORDER.<br />

BEGIN DATA<br />

1045 182 2 155 1 134 1 153 5<br />

1046 155 3 153 5 163 1<br />

1047 161 5 182 2 163 4 186 6<br />

1048 186 2<br />

1049 155 2 163 2 153 2 074 1 161 1<br />

END DATA.<br />

DO IF $CASENUM = 1.<br />

+ PRINT EJECT /’Order’ 1 ’ISBN’ 7 ’Quantity’ 13.<br />

END IF.<br />

PRINT /ORDER 2-5(N) ISBN 8-10(N) QUANTITY 13-17.<br />

EXECUTE.<br />

• This example uses LOOP to simulate a REPEATING DATA command.<br />

• DATA LIST specifies the scratch variable #BKINFO as a string variable (format A) to allow<br />

blanks in the data.<br />

• LOOP is executed if the SUBSTR function returns anything other than a blank or null<br />

value. SUBSTR returns a six-character substring of #BKINFO, beginning with the character<br />

in the position specified by the value of the indexing variable #I. As specified on the<br />

indexing clause, #I begins with a value of 1 and is increased by 6 for each iteration of<br />

LOOP, up to a maximum #I value of 61 (1 + 10 × 6 = 61). The next iteration would exceed<br />

the maximum #I value (1 + 11 × 6 = 67).<br />

Missing Values<br />

• If the program encounters a case with a missing value for the initial, terminal, or increment<br />

value or expression, or if the conditional expression on the LOOP command returns<br />

missing, a zero-trip loop results and control is passed to the first command after the END<br />

LOOP command.<br />

• If a case has a missing value for the conditional expression on an END LOOP command,<br />

the loop is terminated after the first iteration.<br />

• To prevent cases with missing values for any variable used in the loop structure from<br />

entering the loop, use the IF clause on the LOOP command (see third example below).

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

Saved successfully!

Ooh no, something went wrong!