SAS Enterprise Guide: Check the Log Macro
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.
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.
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.
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.
If there are some items specific to your environment that you want to trap – just add it here:
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.
If you want to email the error-ridden log to yourself – uncomment the Attach= line.
Download the ZIP File ContentsDownload 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. I offer this code to the SAS community to use as you will.
Never miss a BI Notes post!
Click here for free subscription. Once you subscribe you'll be asked to confirm your subscription through your email account. You email address is kept private and you can unsubscribe anytime.
Latest posts by Tricia Aanderud (see all)
- Use Network Analysis to Understand Your Customers with SAS Visual Analytics 8.2 - 2018-01-21
- My 7 Favorite Features in SAS Visual Analytics 8.2 on Viya - 2018-01-14
- Creating a Web Analytics Report in SAS Visual Analytics 8.1 - 2017-06-19
- Designing Dashboards: Sending Your Style Vibe - 2017-01-21
- SAS Visual Analytics: Design Versus Reality - 2016-10-05