next up previous
Next: Looking at SAS datasets: Up: Utilities Previous: Utilities

Parsing the SAS log: logsasparse

After a SAS program finishes running, you should read the SAS log to see that there were no errors or unanticipated events. The log may be hundreds or thousands of lines. An easier way is to write a perl script that searches the log for keywords. My perl script is called logsasparse and prints out suspicious lines in the log.

I save this perl program as a file named logsasparse in a directory in my path, and I call it by saying

logsasparse mysasfile.log
The code itself is below:
#!/usr/bin/perl
foreach my $ARG( @ARGV)
{
    open(FH, "<$ARG") || die "$ARG inaccessible: $!";
    while(<FH>)
    {
	print $ARG," :", $.,  " ", $_ if /(not found|multiple lengths|has more than one data set with|overwrit|uninit|warning|no observations|[^_](?<!set )error(?! detection))/i;
    }
    close FH;
}

Particularly insidious errors this catches are when a variable is uninitialized, when a variable is overwritten in a merge, and when a data step merge is many-to-many without your realizing it. These errors are insidious because they are not reported as errors in the log, merely notes or warnings.

As a matter of course, you should have the option MSGLEVEL set to I. See Section 9.3 for details.

One nonobvious thing about this way of doing things is that if you create datasets named ERROR, which, if your program is working correctly, will have zero observations, logsasparse will print out how many observations they contain to the log file.


next up previous
Next: Looking at SAS datasets: Up: Utilities Previous: Utilities
Andre de Souza 2012-11-19