Utility Program for Checking SAS Logs

In the interest of moving repeated tasks in research from the realm of the human to that of the machine, I’ve written a script that checks SAS logs for common errors and prints a summary. I’ve always felt like finding useful information about errors in SAS logs can be like finding a needle in a haystack. The short program is written in Python and I’ve named it checklog.

The name of the log file to check may be supplied as an optional argument; if no arguments are supplied, the program searches the current directory for the most recently written SAS log (ie, a file ending in “.log”).

The major value-added for this program is that I have made a list of SAS problems appearing in logs that seem important but that don’t stop the SAS script from executing — things like creating datasets that are empty or trying to create a variable that already exists, neither of which generally raise ERROR flags in the log. I strip out or summarize WARNING’s and NOTE’s that I have identified as not important (eg, notes that tables have been created), and print any that are unexpected for human review. If the same error, note, or warning appears many times, the program simply prints the message and how many times it appears, saving the human the time of having to search through the log manually for errors only to find the same message repeated throughout. I’ve been using it for several months, and it generally does the job for me of picking out what I need to know to decide whether a program ran as expected from just one glance.

After printing info about potential problems in the log, the program prompts for a y/n response to open the raw log in vi for further human inspection, so if you’re used to opening your logs in vi to read them, this program will offer you a lot of extra quick info at your fingertips for hardly any cost.

Update May 2016. Running the command checklog.py -help prints the following:

checklog.py [file]

file: If supplied, open and check this file for errors or important warnings.
If no file is supplied, then the most recent file in the current directory
is used.

After a check is run, a prompt will appear asking whether to open the log in vi.

Allowed responses to this prompt and their results are:
yes | y opens the log in vi

no | n | :q | ctrl+D closes this program without opening the log

cat will print the log then exit (equivalent to
“cat “)

tail | t will print the log to the screen as it
is being written to by SAS (equivalent
to “tail -f “)

A convenient way to use this program is to alias it. To do this, Alex
puts the following line in ~/.bashrc :
alias checklog=”python /bod/soi2/econ2/ambell/checklog.py ”

Then, he just types the command checklog to call this program in the current
directory.