BookmarkSubscribeRSS Feed
smc2
Calcite | Level 5

How can I create an automated error report from the log?

Is there a simple macro solution to capture this information? On our team, we have drafted a template macro but it is not pulling all the errors from the run only the last error. Also at times the errors are not noticed at all by the macro. Example below

 

I would like to receive an email when the SAS program encounters an error. The email should include the # of errors, program name and list of errors. Are there any other fields that would return the errors or error count or text for each error?

 

/*MACRO TO PRINT ERRS AND SEND EMAIL*/

 

%MACRO TEST();

%IF &SYSERR EQ 0 %THEN %DO;

%PUT NOERROR;

%END;

%ELSE %DO;

filename outbox email cc=("email@email.com")

      subject="XXX &SYSDATE9. Error in program &_CLIENTTASKLABEL."

      type="text/html";

      ods html3 body = outbox style=Minimal;

      ods html3 text="&_CLIENTPROJECTPATH.";

      ODS HTML3 TEXT="&_CLIENTPROCESSFLOWNAME., &_CLIENTPROJECTNAME";

      ods html3 text="SYSERRS: &SYSERR.";

      ods html3 text="SYSERRTEXT: &SYSERRORTEXT.";

      ODS HTML3 TEXT="SYSDBMSG: &SYSDBMSG.";

      ODS HTML3 TEXT="SYSLAST: &SYSLAST.";

 

      title;

footnote;

ods html3 close;

 

      ods msoffice2k  close;

 

%END;

%MEND;

%TEST();

2 REPLIES 2
Quentin
Super User

Hi,

 

In order to return a list of all errors, I think you're stuck scanning the log.

 

If you search lexjansen.com for user papers written about log scanner, log parser, etc, you'll find lots of approaches.

 

My favorite approach is: https://www.lexjansen.com/nesug/nesug01/cc/cc4008.pdf because they take the conservative approach of creating a list of good notes, and assume any note that is not in their white-list is a bad note.

 

I've never really dug into the SAS logging facility ( https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/logug/n09ixzwi752s0cn1m3tvrrhu84ry.htm ) to figure out if it would be useful for this sort of task.  It might be worth a look.

 

--Q.

BASUG is hosting free webinars Next up: Don Henderson presenting on using hash functions (not hash tables!) to segment data on June 12. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
Quentin
Super User

Just to add some more thoughts.

 

I have a log scanner that I use to email me a summary of the log errors/warnings/notes, like you describe.

 

But to be honest, for 99% of my use cases, I could have stopped at it sending me just a single "problems found" notification.  Because regardless of whether there is one error or 20, my first step is usually to open the log.  So having a listing of all errors in the notification doesn't really add much value.

 

If you have scheduled jobs, most schedulers include a feature to check the return code from the SAS session and send an email if it is not 0.

 

I still find log scanning a useful approach, as you can treat warnings and bad notes as errors.  But it's worth thinking about what you really need for a minimum viable error detection report.

 

--Q.

BASUG is hosting free webinars Next up: Don Henderson presenting on using hash functions (not hash tables!) to segment data on June 12. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 318 views
  • 0 likes
  • 2 in conversation