Monday, April 11, 2011

This Page Intentionally Left Blank

Sometimes printed documents will have a message like This Page Intentionally Left Blank. But, of course, since those pages have that message, they really aren't blank.

How can we adapt this to our reporting programs and processes?
  • In a BI environment if, for example, a Stored Process report has no data, then the user will either see a blank page or an error message that no output was generated.
  • In a batch reporting environment where reports are emailed as attachments, if there is no data, the file may not be created and so the code to email the report will likely fail.
Neither of these is particularly user-friendly or desirable. So, how do we handle this? This Page Intentionally Left Blank suggests a solution. Simply produce some output. The macro noDataFoundMessage does just that for you. If the input data set is empty, it produces a page of output with an appropriate message. If the output data set is not empty, it generates no output. When used with your reporting code you are thus guaranteed that some output is produced
  • if you have data, your report is output, but the noDataFoundMessage macro produces no output
  • if there is no data, your report code produces no output, but the noDataFoundMessage does
So the trick is call both your reporting code and the noDataFoundMessage macro. One of the two, but not both, will produce output.

The macro source follows. Feel free to use and share it. I just ask that it's source is acknowledged.

%macro noDataFoundMessage
      Message=No Data Found

Copyright (c) 2008 Henderson Consulting Services
PROGRAMMER : Don Henderson
PURPOSE : Generates a message if the specified
          input data set is empty.

Used to prevent the SAS Stored Process Server
from returning the message that no output was
generated for situations where there is no data.

Can be called immediately after reporting code,
using the same input data set, to produce the
custom message if the input data is empty.

data nodata;
length msg $128;
if lr then
do; /* no data */
   msg = symget("Message");
end; /* no data */
set &data end=lr;

proc report data = nodata nowd;
 columns msg;
 define msg / display ' ';

%mend noDataFoundMessage;