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 post!
Get the latest BI Notes post in your Inbox when a new post is released! Click here for free subscription. You email address is kept private and you can unsubscribe anytime. Go ahead ... join us!
Attending SESUG 2015?
If you are planning to attend SESUG 2015 in beautiful Savannah, Georgia on Sept 29 then join me for my talk about data visualization "How to be the MacGyver of Data Visualization"! I'll show you some cool ways to visualize data with SAS Visual Analytics as well as some traps to avoid.
Latest posts by Tricia Aanderud (see all)
- SAS VA: Is Location just a Distracting Character in Your Dataviz? - August 24, 2015
- Do You KISS Your Line Charts? - August 5, 2015
- How Not Knowing Pie Charts Makes You a #DataViz Rookie - May 7, 2015
- 6 Tips for Data Visualization from a Floral Designer - March 26, 2015
- SAS Coding: Use Flowcharts to Learn Inherited SAS Code - March 2, 2015