Looping and conditional execution in streams
From version 16.0 onwards, SPSS® Modeler enables you to create some basic scripts from within a stream by selecting values within various dialog boxes instead of having to write instructions directly in the scripting language. The two main types of scripts you can create in this way are simple loops and a way to execute nodes if a condition has been met.
You can combine both looping and conditional execution rules within a stream. For example, you may have data relating to sales of cars from manufacturers worldwide. You could set up a loop to process the data in a stream, identifying details by the country of manufacture, and output the data to different graphs showing details such as sales volume by model, emissions levels by both manufacturer and engine size, and so on. If you were interested in analyzing European information only, you could also add conditions to the looping that prevented graphs being created for manufacturers based in America and Asia.
- Looping You can use looping to automate repetitive tasks.
For example, this might mean adding a given number of nodes to a stream
and changing one node parameter each time. Alternatively, you could
control the running of a stream or branch again and again for a given
number of times, as in the following examples:
- 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.
- Conditional Execution You can use this to control how terminal
nodes are run, based on conditions that you predefine, examples may
include the following:
- Based on whether a given value is true or false, control if a node will be run.
- Define whether looping of nodes will be run in parallel or sequentially.
Both looping and conditional execution are set up on the Execution tab within the Stream Properties dialog box. Any nodes that are used in conditional or looping requirements are shown with an additional symbol attached to them on the stream canvas to indicate that they are taking part in looping and conditional execution.
You can access the Execution tab in one of 3 ways:
- Using the menus at the top of the main dialog box:
- From the Tools menu, choose:
- Click the Execution tab to work with scripts for the current stream.
- From the Tools menu, choose:
- From within a stream:
- Right-click on a node and choose Looping/Conditional Execution.
- Select the relevant submenu option.
- From the graphic toolbar at the top of the main dialog box, click the stream properties icon.
If this is the first time you have set up either looping or conditional execution details, on the Execution tab select the Looping/Conditional Execution execution mode and then select either the Conditional or Looping subtab.