DATA Step, Macro, Functions and more

The %check_for_warnings and STOP! SAS Macro

Reply
Occasional Contributor
Posts: 7

The %check_for_warnings and STOP! SAS Macro

Here's a little macro I developed that you can call anywhere in your SAS program to check to see if any warning messages have been issued in the SAS log up to that point.  If a warning message has been issued, this macro gracefully terminates the SAS program at that point.  Why would you want to do this?  Here's an example.  I have a program that creates a dashboard using ODS LAYOUT with ODS graphics, SAS/GRAPH, PROC REPORT, and other procedures under the hood.  Sometimes, the data you are receiving or extracting can cause unanticipated changes in your dashboard.  For example, a table might be suppressed because it suddenly has more rows than you have ever had before and it no longer fits in the region allotted to it, requiring some changes to the dashboard.  Do you really want to email out to dozens of people a dashboard report that is malformed or missing whole sections?  Of course not!  Chances are, when this happens, SAS has issued one or more warning messages, and this macro will allow you to abort the program before the report is emailed out or otherwise distributed.

******************************************;

* Macro Name: %check_for_warnings        *;
* Last Updated: 12/04/14 by David Oesper *;

******************************************;

%macro check_for_warnings;
%if %sysevalf(%superq(syswarningtext) ne,boolean) %then %do;

   %if %superq(syswarningtext) ne Warning message encountered, terminating SAS program %then %do;

      %put WARNING: Warning message encountered, terminating SAS program;
      %abort cancel;
   %end;

%end;
%mend check_for_warnings;
.
.
.
%check_for_warnings;  /* located at a point in your program where you want to terminate your SAS program if any warning has occurred, for example, right before an email step */

Acknowledgements: The SAS Global Forum 2009 paper 022-2009 Is This Macro Parameter Blank? by Chang Chung & John King (http://changchung.com/download/022-2009.pdf) was very helpful in the preparation of this macro.

Ask a Question
Discussion stats
  • 0 replies
  • 196 views
  • 0 likes
  • 1 in conversation