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<br />

LOOP [varname=n TO m [BY {1**}]] [IF [(]logical expression[)]]<br />

{n }<br />

transformation commands<br />

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

**Default if the subcommand is omitted.<br />

Examples<br />

SET MXLOOPS=10. /*Maximum number of loops allowed<br />

LOOP. /*Loop with no limit other than MXLOOPS<br />

COMPUTE X=X+1.<br />

END LOOP.<br />

LOOP #I=1 TO 5. /*Loop five times<br />

COMPUTE X=X+1.<br />

END LOOP.<br />

Overview<br />

The LOOP—END LOOP structure performs repeated transformations specified by the commands<br />

within the loop until they reach a specified cutoff. The cutoff can be specified by an<br />

indexing clause on the LOOP command, an IF clause on the END LOOP command, or a<br />

BREAK command within the loop structure (see BREAK). In addition, the maximum number<br />

of iterations within a loop can be specified on the MXLOOPS subcommand on SET. The<br />

default MXLOOPS is 40.<br />

The IF clause on the LOOP command can be used to perform repeated transformations<br />

on a subset of cases. The effect is similar to nesting the LOOP—END LOOP structure within<br />

a DO IF—END IF structure, but using IF on LOOP is simpler and more efficient. You have to<br />

use the DO IF—END IF structure, however, if you want to perform different transformations<br />

on different subsets of cases. You can also use IF on LOOP to specify the cutoff, especially<br />

when the cutoff may be reached before the first iteration.<br />

LOOP and END LOOP are usually used within an input program or with the VECTOR command.<br />

Since the loop structure repeats transformations on a single case or on a single input<br />

record containing information on multiple cases, it allows you to read complex data files or<br />

to generate data for a working data file. For more information, see INPUT PROGRAM—END<br />

INPUT PROGRAM and VECTOR.<br />

The loop structure repeats transformations on single cases across variables. It is different<br />

from the DO REPEAT—END REPEAT structure, which replicates transformations on a<br />

specified set of variables. When both can be used to accomplish a task, such as selectively<br />

transforming data for some cases on some variables, LOOP and END LOOP are generally<br />

more efficient and more flexible, but DO REPEAT allows selection of nonadjacent variables<br />

and use of replacement values with different intervals.<br />

830

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

Saved successfully!

Ooh no, something went wrong!