It can be a challenge to know how to handle an empty input data set, especially when automating projects that run in batch. For example, when an empty input data set is used in a results-generating task, the results will display the last non-empty results, instead of indicating that the results are empty. And, if the task Export as a Step in Project is used to automatically send the results-generating task results, then the task will export the prior non-empty report results, instead of indicating that the current results are empty.
This sample explains how to workaround this behavior by using the Conditional Processing task to conditionally branch within a Process Flow based on the value of a parameter, the current date or time, and the first or last value of a column in a data set.
This sample first shows how to use SAS code to determine when an input data set is empty, and, then, secondly, it shows how to conditionally branch processing in the Process Flow based on whether the input data set is empty. If the input data set is not empty, then normal processing will occur. If the input data set is empty, then a different report will be sent, indicating that the input data set was empty.
For more information about using SAS Enterprise Guide, see the SAS Enterprise Guide documentation page.
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
This code is the same as the first code node in the project attached in the Downloads section of this sample.
Step 1 creates SAMPLE data.
Step 2 filters SAMPLE data as an easy way to create an empty or non-empty INPUT data set.
Step 3 determines if the INPUT data set is empty or not. If the INPUT data set is empty, then the DATA step generates a one-row data set with a single column called ROW with a value of 'empty'. If the INPUT data set is not empty, then the DATA step regenerates the INPUT data set and adds a new column called ROWS with each value being 'not empty'.
This code will run "as is".
/* Step 1 */
data sample;
input age height;
cards;
10 50
11 51
12 55
13 60
14 62
15 65
16 70
;
run;
/* Step 2 */
/* To see how the conditional processing node works, switch between '< 20' and '> 20' */
/* Using '< 20' will result in a non-empty data set. Using '> 20' will result in an empty data set. */
data input;
set sample;
where age < 20;
run;
/* Step 3 */
%let dsid=%sysfunc(open(work.input));
%let nobs=%sysfunc(attrn(&dsid,nobs));
%let rc=%sysfunc(close(&dsid));
/* The value of the column ROWS will be used in the conditional processing node to determine */
/* which branch should be executed. */
data branch;
length rows $10;
if &nobs = 0 then rows = 'empty';
else do;
set input;
rows = 'not empty';
end;
run;
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
Follow these steps to use the attached sample project.
Zip file containing the Project file.
This display shows the Process Flow of the sample project.
The check mark on the Summary Statistics task and the X on the Empty program node indicates a Condition is associated with each.
The check mark indicates that the branch was executed and the X indicates that the branch was not executed.
Right-click on the Summary Statistics task and choose Condition, then Edit.
This display shows the Conditional Processing task.
Select the condition, First value: rows equal to 'not empty', then click Edit.
This display shows the condition in more detail.
This display shows the results generated by running the Summary Statistics task branch.
This display shows the Empty program node branch is executed because the input data set was empty.
Notice the dashed line between the Branch data node and the Empty program node. That line is created when you right-click on a node in the Process Flow to Link to another node.
This step was required so that the Empty program node could be included in the Conditional Processing task.
This display shows the results generated when the Process Flow is run and the INPUT data set is empty.
Type: | Sample |
Date Modified: | 2018-06-11 16:09:31 |
Date Created: | 2010-06-15 09:24:55 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | SAS Enterprise Guide | Microsoft® Windows® for 64-Bit Itanium-based Systems | ||
Microsoft Windows XP 64-bit Edition | ||||
Microsoft Windows 8 Enterprise 32-bit | ||||
Microsoft Windows 8 Enterprise x64 | ||||
Microsoft Windows 8 Pro 32-bit | ||||
Microsoft Windows 8 Pro x64 | ||||
Microsoft Windows 8.1 Enterprise 32-bit | ||||
Microsoft Windows 8.1 Enterprise x64 | ||||
Microsoft Windows 8.1 Pro 32-bit | ||||
Microsoft Windows 8.1 Pro x64 | ||||
Microsoft Windows 10 | ||||
Microsoft Windows Server 2008 | ||||
Microsoft Windows Server 2008 R2 | ||||
Microsoft Windows Server 2012 Datacenter | ||||
Microsoft Windows Server 2012 R2 Datacenter | ||||
Microsoft Windows Server 2012 R2 Std | ||||
Microsoft Windows Server 2012 Std | ||||
Microsoft Windows Server 2016 | ||||
Windows 7 Enterprise 32 bit | ||||
Windows 7 Enterprise x64 | ||||
Windows 7 Home Premium 32 bit | ||||
Windows 7 Home Premium x64 | ||||
Windows 7 Professional 32 bit | ||||
Windows 7 Professional x64 | ||||
Windows 7 Ultimate 32 bit | ||||
Windows 7 Ultimate x64 |