PRINT Subcommand (DO REPEAT-END REPEAT command)

The PRINT subcommand on END REPEAT displays the commands generated by the DO REPEAT—END REPEAT structure. PRINT can be used to verify the order in which commands are executed.

Example

DO REPEAT Q=Q1 TO Q5/ R=R1 TO R5.
COMPUTE Q=0.
COMPUTE R=1.
END REPEAT PRINT.
  • The DO REPEAT—END REPEAT structure initializes one set of variables to 0 and another set to 1.
  • The output from the PRINT subcommand is shown below. The generated commands are preceded by plus signs.
  • The COMPUTE commands are generated in such a way that variables are created in alternating order: Q1, R1, Q2, R2, and so forth. If you plan to use the TO keyword to refer to Q1 to Q5 later, you should use two separate DO REPEAT utilities; otherwise, Q1 to Q5 will include four of the five R variables. Alternatively, use the NUMERIC command to predetermine the order in which variables are added to the active dataset, or specify the replacement value lists as shown in the next example.
Figure 1. Output from the PRINT subcommand

  2	  0	      DO REPEAT Q=Q1 TO Q5/ R=R1 TO R5
  3	  0	      COMPUTE Q=0
  4	  0	      COMPUTE R=1
  5	  0	      END REPEAT PRINT
 
  6	  0	     +COMPUTE Q1=0
  7	  0	     +COMPUTE R1=1
  8	  0	     +COMPUTE Q2=0
  9	  0	     +COMPUTE R2=1
 10	  0	     +COMPUTE Q3=0
 11	  0	     +COMPUTE R3=1
 12	  0	     +COMPUTE Q4=0
 13	  0	     +COMPUTE R4=1
 14	  0	     +COMPUTE Q5=0
 15	  0	     +COMPUTE R5=1

Example

DO REPEAT Q=Q1 TO Q5,R1 TO R5/ N=0,0,0,0,0,1,1,1,1,1.
COMPUTE Q=N.
END REPEAT PRINT.
  • In this example, a series of constants is specified as a stand-in value list for N. All the Q variables are initialized first, and then all the R variables, as shown below.
Figure 2. Output from the PRINT subcommand

  2	  0	           DO REPEAT Q=Q1 TO Q5,R1 TO R5/ N=0,0,0,0,0,1,1,1,1,1
  3	  0	           COMPUTE Q=N
  4	  0	           END REPEAT PRINT

  5	  0	          +COMPUTE Q1=0
  6	  0	          +COMPUTE Q2=0
  7	  0	          +COMPUTE Q3=0
  8	  0	          +COMPUTE Q4=0
  9	  0	          +COMPUTE Q5=0
 10	  0	          +COMPUTE R1=1
 11	  0	          +COMPUTE R2=1
 12	  0	          +COMPUTE R3=1
 13	  0	          +COMPUTE R4=1
 14	  0	          +COMPUTE R5=1

Example

DO REPEAT R=REGION1 TO REGION5/ X=1 TO 5.
COMPUTE R=REGION EQ X.
END REPEAT PRINT.
  • In this example, stand-in variable R represents the variable list REGION1 to REGION5. Stand-in variable X represents the value list 1 to 5.
  • The DO REPEAT—END REPEAT structure creates dummy variables REGION1 to REGION5 that equal 0 or 1 for each of 5 regions, depending on whether variable REGION equals the current value of stand-in variable X.
  • PRINT on END REPEAT causes the program to display the commands generated by the structure, as shown below.
Figure 3. Commands generated by DO REPEAT

  2	  0	  DO REPEAT R=REGION1 TO REGION5/ X=1 TO 5
  3	  0	  COMPUTE R=REGION EQ X
  4	  0	  END REPEAT PRINT
 
  5	  0	 +COMPUTE REGION1=REGION EQ 1
  6	  0	 +COMPUTE REGION2=REGION EQ 2
  7	  0	 +COMPUTE REGION3=REGION EQ 3
  8	  0	 +COMPUTE REGION4=REGION EQ 4
  9	  0	 +COMPUTE REGION5=REGION EQ 5