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.

510 END CASE<br />

Example<br />

• COMPUTE sets X equal to each of the scratch variables. END CASE tells the program to<br />

build a case. Thus, the first loop (for the first case) sets X equal to the first element of vector<br />

V. Since V(1) references #X1, and #X1 is 2, the value of X is 2. Variable X is then formatted<br />

and printed before control returns to the command END LOOP. The loop<br />

continues, since indexing is not complete. Thus, the program then sets X to #X2, which is<br />

1, builds the second case, and passes it to the FORMAT and PRINT commands. After the<br />

third iteration, which sets X equal to 1, the program formats and prints the case and terminates<br />

the loop. Since the end of the file has not been encountered, END INPUT<br />

PROGRAM passes control to the first command in the input program, DATA LIST, to read<br />

the next input case. After the second loop, however, the program encounters END DATA<br />

and completes building the working data file.<br />

• The six new cases are shown in Figure 1.<br />

Figure 1 Outcome for multiple cases read from a single case<br />

2<br />

1<br />

1<br />

3<br />

5<br />

1<br />

*Restructuring a data file to create a separate case for<br />

each book order.<br />

INPUT PROGRAM.<br />

DATA LIST /ORDER 1-4 #X1 TO #X22 (1X,11(F3.0,F2.0,1X)).<br />

LEAVE ORDER.<br />

VECTOR BOOKS=#X1 TO #X22.<br />

LOOP #I=1 TO 21 BY 2 IF NOT SYSMIS(BOOKS(#I)).<br />

- COMPUTE ISBN=BOOKS(#I).<br />

- COMPUTE QUANTITY=BOOKS(#I+1).<br />

- END CASE.<br />

END LOOP.<br />

END INPUT PROGRAM.<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 />

SORT CASES ISBN.<br />

DO IF $CASENUM EQ 1.<br />

- PRINT EJECT /’Order ISBN Quantity’.<br />

- PRINT SPACE.<br />

END IF.<br />

FORMATS ISBN (F3)/ QUANTITY (F2).<br />

PRINT /’ ’ ORDER ’ ’ ISBN ’ ’ QUANTITY.<br />

EXECUTE.

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

Saved successfully!

Ooh no, something went wrong!