Running Conditional Processes

Overview

The Conditional Start and Conditional End transformations support conditional flow processing within a SAS Data Integration Studio job. The Conditional Start transformation uses SAS macro %if logic. You can define distinct portions of a job to run conditionally, based on whether the associated defined condition is determined to be true or false. Job flow is sequential and multiple conditions can be defined within the same job that might or might not be logically related to one another. Each conditional definition block that you create starts and ends a task or series of tasks that run if the defined condition is true.
If you need to include a Return Code Check transformation in a job that contains the Conditional Start and Conditional End transformations, place it in one of the following locations:
  • after the transformations that are being processed between the Conditional Start and Conditional End transformations
  • after the Conditional End transformation

Problem

You want to run one or more sections of a SAS Data Integration Studio job as a conditional process.

Solution

You can use the Conditional Start and Conditional End transformations to define sections of the job that processed conditionally. For example, you can create a job that sorts an input table for country whenever the job is run after the first 15 days of the current month. The input table and Sort transformation in this job are placed between Conditional Start and Conditional End transformations to define a conditional process. Then, a condition is set in the Conditional Start transformation to specify the days in the month in which the process can be run. This sample job includes the following tasks:

Tasks

Create and Configure the Job

The following display shows a simple job that sorts a table of customer data by country:
Sort Job
Sort Job
You can review the initial, unsorted data for the Customer source table, as shown in the following display:
Customer Source Table
Customer Source Table
You can add the Conditional Start and Conditional End transformations to a SAS Data Integration Studio job to create a conditional definition block.
Note that the Conditional Start and Conditional End transformations do not yet enclose the Sort transformation and the Customer table in the following display:
Conditional Transformations
Conditional Transformations
You must reorder the contents of the Diagram tab to define the conditional definition block.
Use the Control Flow tab reorder these contents, as shown in the following display:
Control Flow Tab
Control Flow Tab
Note that the tab shows the transformations in the following order: Conditional Start, Sort, and Conditional End.
The following display shows the reordered flow on the Diagram tab:
Reordered Conditional Transformations
Ordered Conditional Transformations
Now that the job in is enclosed in the conditional definition block, the condition can be defined in the Condition tab, as shown in the following display:
Condition Tab
Condition Tab
The condition input in the Condition tab in the is processed by the %eval (Condition) function in the generated code of the transformation. You can click on the function in the Functions pane to see a description.

Run the Job and View the Output

Right-click on an empty area of the job, and click Run in the pop-up menu. SAS Data Integration Studio generates code for the job and submits it to the SAS Application Server for execution. You can check the Status tab to verify that the job completes successfully and that the condition flow is executed.
The Status tab is shown in the following display:
Job Status
Job Status
You can also verify that output changed in accordance with the condition, as shown in the following display:
Conditional Output
Conditional Output
In this case, the output is sorted by country This result is expected because the expression in the Condition tab was executed.