BookmarkSubscribeRSS Feed
DavidOesper
Fluorite | Level 6

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 0 replies
  • 886 views
  • 0 likes
  • 1 in conversation