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.

Example<br />

DO REPEAT—END REPEAT 503<br />

• The five variables are initialized to 0 by a single COMPUTE specification that is repeated<br />

for each variable on the replacement list. Thus, the program generates five COMPUTE<br />

commands from the one specified.<br />

• Stand-in variable R ceases to exist once control passes out of the DO REPEAT structure.<br />

* This example shows a typical application of INPUT PROGRAM, LOOP,<br />

and DO REPEAT. A data file containing random numbers is generated.<br />

INPUT PROGRAM.<br />

+ LOOP #I = 1 TO 1000.<br />

+ DO REPEAT RESPONSE = R1 TO R400.<br />

+ COMPUTE RESPONSE = UNIFORM(1) > 0.5.<br />

+ END REPEAT.<br />

+ COMPUTE AVG = MEAN(R1 TO R400).<br />

+ END CASE.<br />

+ END LOOP.<br />

+ END FILE.<br />

END INPUT PROGRAM.<br />

FREQUENCIES VARIABLE=AVG<br />

/FORMAT=CONDENSE<br />

/HISTOGRAM<br />

/STATISTICS=MEAN MEDIAN MODE STDDEV MIN MAX.<br />

• The INPUT PROGRAM—END INPUT PROGRAM structure encloses an input program that<br />

builds cases from transformation commands.<br />

• The indexing variable (#I) on LOOP—END LOOP indicates that the loop should be executed<br />

1000 times.<br />

• The DO REPEAT—END REPEAT structure generates 400 variables, each with a 50%<br />

chance of being 0 and a 50% chance of being 1. This is accomplished by specifying a<br />

logical expression on COMPUTE that compares the values returned by UNIFORM(1) to the<br />

value 0.5. (UNIFORM(1) generates random numbers between 0 and 1.) Logical expressions<br />

are evaluated as false (0), true (1), or missing. Thus, each random number returned<br />

by UNIFORM that is 0.5 or less is evaluated as false and assigned the value 0, and each<br />

random number returned by UNIFORM that is greater than 0.5 is evaluated as true and<br />

assigned the value 1.<br />

• The second COMPUTE creates variable AVG, which is the mean of R1 to R400 for each<br />

case.<br />

• END CASE builds a case with the variables created within each loop. Thus, the loop structure<br />

creates 1000 cases, each with 401 variables (R1 to R400, and AVG).<br />

• END FILE signals the end of the data file generated by the input program. If END FILE were<br />

not specified in this example, the input program would go into an infinite loop. No<br />

working file would be built, and the program would display an error message for every<br />

procedure that follows the input program.<br />

• FREQUENCIES produces a condensed frequency table, histogram, and statistics for AVG.<br />

The histogram for AVG shows a normal distribution.

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

Saved successfully!

Ooh no, something went wrong!