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, andSELECT IF - Data declarations:
VECTOR,STRING,NUMERIC, andLEAVE - Data definition:
DATA LIST,MISSING VALUES(but notVARIABLE LABELSorVALUE LABELS) - Loop structure commands:
LOOP,END LOOP, andBREAK - Do-if structure commands:
DO IF,ELSE IF,ELSE, andEND IF - Print and write commands:
PRINT,PRINT EJECT,PRINT SPACE, andWRITE - Format commands:
PRINT FORMATS,WRITE FORMATS, andFORMATS
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 REPEATcommand. 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 REPEATstructure 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 sameDO REPEATstructure. - A replacement variable list can include either new or existing variables. You cannot mix new and existing variables in the same replacement list.
- Keyword
TOcan be used to name consecutive existing variables and to create a set of new variables, and keywordALLcan be used to specify all variables. - New string variables must be declared on the
STRINGcommand either beforeDO REPEATor within theDO REPEATstructure. - 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
TOn 2, where n 1 is less than n 2 and both are integers. (Note that the keyword isTO, notTHRU.)
Operations
-
DO REPEATmarks the beginning of the control structure andEND REPEATmarks 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 REPEATandEND REPEATonce 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.2format. - New string
variables declared within the structure are initially set to a blank
value and are assigned the format specified on the
STRINGcommand that creates them. - If
DO REPEATis used to create new variables, the order in which they are created depends on how the transformation commands are specified. Variables created by specifying theTOkeyword (for example, V1TOV5) 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.