SAS Enterprise Guide: Check the Log Macro

This post was kindly contributed by Business Intelligence Notes for SAS® BI Users - go there to comment and to read the full post.

I created a LogCheck macro [code provided] to review the log during a batch process. The SAS log files can be rather large and it is so much easier if you can just extract the issues in an easy to understand format. This macro reads in each line of the log file and keeps the ones with Error, Warning, Note, or specific text you want to trap.  Then it sends a colorful email to report what issues (if any) were found.

You can download the code and two sample programs to review or change for your situation.  Let me know what you think in the Comments section.  How can the code be improved?  Any ideas you have?  

Using the LogCheck Macro

Add the LogCheck macro to your batch job to report issues through email about the job.  When the job has no errors, you will receive an email similar to the following.  The subject line indicates no found issues – thus you have some assurance the job was successful.

0402 logcheck 01 SAS Enterprise Guide: Check the Log Macro

When the job has errors – the macros sends an email similar to the following.  Notice the subject line contains the number of Errors, Warnings, and Notes present in the log. The email lists each issue, where found in the log, and an excerpt from the log.  This makes it easier to determine if an error early on in the job actually caused the other errors and you can quickly fix the root cause.

0402 logcheck 02 SAS Enterprise Guide: Check the Log Macro

Adding the Macro to Your Code

CheckLog was designed to run with a batch job. To use this program, do the following:

1. Add the following code to the top of the SAS program you want to monitor.  Update the LogName macro variable to the location and name of your log file. Refer to the PROC PRINTTO documentation if you need more guidance.

       /* ==================================================================*/ 

       %let LogName=%QUOTE(path\file_log_name.log); 

       proc printto log="&LogName." new; run; 

       /* ==================================================================*/
            

2. Add this code to the bottom.  No changes required. 

      /* ==================================================================*/ 

       %let RUNDATE=%SYSFUNC( DATETIME(), DATETIME18. ); 

       %put PASS HEADER DATE=&RUNDATE.;  

        

       proc printto; run; 

       %logcheck(&logname.) 

       /* ==================================================================*/ 

3. In the LogCheck_macro.sas – update the EMAIL macro variable to send to the email address of your choice.  After making this change – run the two test programs (included in the download) to see how it works.  

0402 logcheck 03 SAS Enterprise Guide: Check the Log Macro

Change it Up for Your Environment 

I have the code check for Notes that actually can produce errors but do not stop production.  This can be annoying if it is something you do not care about – so you may want to prune this area of the code.

0402 logcheck 04 SAS Enterprise Guide: Check the Log Macro

If there are some items specific to your environment that you want to trap – just add it here:

0402 logcheck 05 SAS Enterprise Guide: Check the Log Macro

Some issues present as errors/warnings but may not be in reality.  For instance, Teradata generates a Warning that it cleared the table – which is what you want to happen.  It’s not an issue.  So use this area of the code to change the type.  A TYPE=4 is a NOTE and will show as gray in the email.  Otherwise it will be a Type=2 that is bright yellow.  Since a Type=4 generates an email that indicates an issue- you may want to delete this line.

0402 logcheck 06 SAS Enterprise Guide: Check the Log Macro

If you want to email the error-ridden log to yourself – uncomment the Attach= line.

0402 logcheck 07 SAS Enterprise Guide: Check the Log Macro

Download the ZIP File Contents

 

Download CheckLog Macro

There are three files in the ZIP file:

  • Checklog_macro.sas  /*Code – Offered AS IS*/
  • Program_wErrors.sas  /*Outputs the email with many errors*/
  • Prgoram_wNoErrors.sas  /*Outputs a clean email*/

The two Program files demonstrate how the Checklog_macro.sas program works. So modify the checklog_macro.sas program to add your email address and then run the program. If you do not have email setup at your site – obviously this won’t be a great option for you. [Reference: SAS Global Forum Paper about Emailing from SAS]

Are there other Log Check Programs?

There are many other (probably superior) log check programs available from the SAS Global Forum papers and in other locations. If you know of another logcheck program – leave a comment and a link if you know where. I offer this code to the SAS community to use as you will.

This post was kindly contributed by Business Intelligence Notes for SAS® BI Users - go there to comment and to read the full post.