Overview (DO REPEAT-END REPEAT command)

The DO REPEAT—END REPEAT structure repeats the same transformations on a specified set of variables, reducing the number of commands you must enter to accomplish a task. This utility does not reduce the number of commands the program executes, just the number of commands you enter. To display the expanded set of commands the program generates, specify PRINT on END REPEAT.

DO REPEAT uses a stand-in variable to represent a replacement list of variables or values. The stand-in variable is specified as a placeholder on one or more transformation commands within the structure. When the program repeats the transformation commands, the stand-in variable is replaced, in turn, by each variable or value specified on the replacement list.

The following commands can be used within a DO REPEAT—END REPEAT structure:

  • Data transformations: COMPUTE, RECODE, IF, COUNT, and SELECT IF
  • Data declarations: VECTOR, STRING, NUMERIC, and LEAVE
  • Data definition: DATA LIST, MISSING VALUES (but not VARIABLE LABELS or VALUE LABELS)
  • Loop structure commands: LOOP, END LOOP, and BREAK
  • Do-if structure commands: DO IF, ELSE IF, ELSE, and END IF
  • Print and write commands: PRINT, PRINT EJECT, PRINT SPACE, and WRITE
  • Format commands: PRINT FORMATS, WRITE FORMATS, and FORMATS

Basic Specification

The basic specification is DO REPEAT, a stand-in variable followed by a required equals sign and a replacement list of variables or values, and at least one transformation command. The structure must end with the END REPEAT command. On the transformation commands, a single stand-in variable represents every variable or value specified on the replacement list.

Syntax Rules

  • Multiple stand-in variables can be specified on a DO REPEAT command. Each stand-in variable must have its own equals sign and associated variable or value list and must be separated from other stand-in variables by a slash. All lists must name or generate the same number of items.
  • Stand-in variables can be assigned any valid variable names: permanent, temporary, scratch, system, and so forth. A stand-in variable does not exist outside the DO REPEAT—END REPEAT structure and has no effect on variables with the same name that exist outside the structure. However, two stand-in variables cannot have the same name within the same DO REPEAT structure.
  • A replacement variable list can include either new or existing variables. You cannot mix new and existing variables in the same replacement list.
  • Keyword TO can be used to name consecutive existing variables and to create a set of new variables, and keyword ALL can be used to specify all variables.
  • New string variables must be declared on the STRING command either before DO REPEAT or within the DO REPEAT structure.
  • All replacement variable and value lists must have the same number of items.
  • A replacement value list can be a list of strings or numeric values, or it can be of the form n 1 TO n 2, where n 1 is less than n 2 and both are integers. (Note that the keyword is TO, not THRU.)

Operations

  • DO REPEAT marks the beginning of the control structure and END REPEAT marks the end. Once control passes out of the structure, all stand-in variables defined within the structure cease to exist.
  • The program repeats the commands between DO REPEAT and END REPEAT once for each variable or value on the replacement list.
  • Numeric variables created within the structure are initially set to the system-missing value. By default, they are assigned an F8.2 format.
  • New string variables declared within the structure are initially set to a blank value and are assigned the format specified on the STRING command that creates them.
  • If DO REPEAT is used to create new variables, the order in which they are created depends on how the transformation commands are specified. Variables created by specifying the TO keyword (for example, V1 TO V5) are not necessarily consecutive in the active dataset. See the topic PRINT Subcommand (DO REPEAT-END REPEAT command) for more information.
  • Multiple replacement lists are stepped through in parallel, not in a nested fashion, and all replacement lists must name or generate the same number of items.