Conditional Execution in DI Studio
DI Studio V4.8 includes, for the first time, facilities to allow parts of a job to be executed conditionally. Previously, conditional execution had to be done either at a lower level (typically within a user-written code node) or at a higher level (typically using a system of triggers to run complete jobs conditionally within a job flow).
The Control section in the list of transformations now includes “Conditional Start” and “Conditional End”. Here is a simple example of their use, incompletely written at this stage:
Notice first the use of “yellow stickies”, available via menu options “Actions”, “Sticky Note”. Use of these is strongly recommended when jobs get complicated – whether the complication lies within nodes or, as here, in the relationships between nodes.
Node 2 here is a “Conditional Start”, and node 3 a “Conditional End”. Whatever lies between them is to be executed if the condition in the “Conditional Start” node evaluates to “true”. In this example it is only a single node that is to be executed conditionally, but it could be several nodes – or it would be possible to include a complete job here.
The condition within the “Conditional Start” node is expressed in SAS Macro language. Here it looks like this:
Testing for existence of a table could use a condition like “%sysfunc(exist(WORK.MYFILE))”.
The second “Conditional Start” node has had its condition entered (“&numrecs = 0”) but is still marked with a red warning sign. This is because the matching “Conditional End” is missing. Once that is added, then a green tick will appear.
One problem will remain, however. Notice that the two User-Written nodes to be executed conditionally both lack step numbers. Just lying physically between the Conditional Start and Conditional End nodes on the job diagram is not enough to specify that they are to be conditionally executed. On the “Control Flow” tab, those two nodes will have yellow warning triangles beside them. It is necessary to go to that tab, and move rows up and down to explicitly specify the correct order for execution:
The numbers on the diagram will now all be correct, and the job can be run. In this case, the parameter to the first user-written code node is specifying a name for which there are two matching rows in the table. After running the job, the “Status” tab shows, for each conditional branch, whether it was executed or not.