Pages

Tuesday, 2 October 2012

NOTE: Conditional Processing, Beyond the Basics With Enterprise Guide

In my preceding Enterprise Guide (EG) "Beyond the Basics" article I described Prompts, their uses, and their benefits. Another valuable feature of EG is conditional Processing. This gives you the ability to take different paths through your project based upon the value of macro variables, prompts, data set contents, and a number of other values.

EG conditions can be associated with executable tasks and programs and are evaluated prior to execution of the task, query or program. Conditions decide which tasks, queries and programs should or should not be executed. Conditions provide a kind-of IF-THEN-ELSE capability in EG.

Once you've added a condition to your process flow you'll notice a few extra indicators appear on your nodes. A small flag indicates that the node has a condition associated with it; a small number indicates the specific condition associated with the specific node (one condition can be associated with more than one node; you'll see the same number of the nodes); a tick or a cross will show whether the condition ran at run-time.

You can make your conditions quite complex because you are allowed to create chains of ELSE-IF clauses within your conditions.

All of this functionality, introduced in EG v4.2, means you can make your EG project produce different reports, send output to different email recipients, and much more.

Curiously, there doesn't seem to be a great deal of talk about EG conditions in conference papers and blogs. SAS Knowledge Base article 39995 offers some useful insight. Chris Hemedinger's SAS Global Forum (SGF) paper from 2008, Find Out What You're Missing: Programming with SAS Enterprise Guide, offers an example. However, Chris Schacherer's excellent SGF paper this year, Take a Fresh Look at SAS Enterprise Guide: From point-and-click ad hocs to robust enterprise solutions, takes a detailed look at many EG features and provides a detailed step-by-step solution to a fictitious reporting scenario, including the use of a condition.

Having extolled the virtues of conditional processing (and, there are many virtues), I need to add a word of caution. If you export the code from the project, the conditional logic will not be included in the export. This is perhaps understandable because conditions are evaluated within EG (on the client) at run-time; they are not implemented in macro code as you might have otherwise supposed. However, the biggest crime here is that EG doesn't warn you that it won't include your conditional logic when you perform an export. You have been warned!