Looping in streams

With looping you can automate repetitive tasks in streams; examples may include the following:

  • Run the stream a given number of times and change the source each time.
  • Run the stream a given number of times, changing the value of a variable each time.
  • Run the stream a given number of times, entering one extra field on each execution.
  • Build a model a given number of times and change a model setting each time.

You set up the conditions to be met on the Looping subtab of the stream Execution tab. To display the subtab, select the Looping/Conditional Execution execution mode.

Any looping requirements that you define will take effect when you run the stream, if the Looping/Conditional Execution execution mode has been set. Optionally, you can generate the script code for your looping requirements and paste it into the script editor by clicking Paste... in the bottom right corner of the Looping subtab; the main Execution tab display changes to show the Default (optional script) execution mode with the script in the top part of the tab. This means that you can define a looping structure using the various looping dialog box options before generating a script that you can customize further in the script editor. Note that when you click Paste... any conditional execution requirements you have defined will also be displayed in the generated script.

Important: The looping variables that you set in a SPSS® Modeler stream may be overridden if you run the stream in a IBM® SPSS Collaboration and Deployment Services job. This is because the IBM SPSS Collaboration and Deployment Services job editor entry overrides the SPSS Modeler entry. For example, if you set a looping variable in the stream to create a different output file name for each loop, the files are correctly named in SPSS Modeler but are overridden by the fixed entry entered on the Result tab of the IBM SPSS Collaboration and Deployment Services Deployment Manager.

To set up a loop

  1. Create an iteration key to define the main looping structure to be carried out in a stream. See Create an iteration key for more information.
  2. Where needed, define one or more iteration variables. See Create an iteration variable for more information.
  3. The iterations and any variables you created are shown in the main body of the subtab. By default, iterations are executed in the order they appear; to move an iteration up or down the list, click on it to select it then use the up or down arrow in the right hand column of the subtab to change the order.