Return to Homepage

Goto the Tip of the Month Archive

Other interesting pages ...
LinkedIn Profile
SAS Cheat Sheet
Useful SAS Code
Full SAS Example
Basic Statistics
Contact Information

SAS Tip of the Month
August 2014
(for SAS)

Like a builder comes to work with some tools, a SAS Programmer carries some tools as well. The three key tools I consider most important are a notebook (taking notes of that piece of code that you found interesting), SAS manual(s) in PDF format, a simple text editor and a LOG Checker. The last one may seem strange but the SAS LOG has everything about the SAS Program that ran, right on down to number of observations used in each step. But the SAS LOG can be long, and manually checking such a file is next to impossible, hence an electronic checker.

Below is a SAS program that I use (I have a slightly more advanced version but this is Old Faithful) reproduced below:

*Define location of LOG Files to process;
%let logdir=%str(C:\temp\tables);

*Bring in ALL SAS LOG(s);
data _alllogs0;
   attrib _txt length=$256 informat=$char256.
   _fn length=$256
   _myinfile length=$256
   _ln length=8
   _myinline length=8;
   infile "&logdir.\t*.log" /*Here use t*.log for all table LOGS but can be anything e.g. l*.log */
      lrecl=256 filename=_myinfile
      line=_myinline length=len;
      input _txt $varying256. len;
proc sort data=_alllogs0;
   by _fn _ln;

*Output findings;
title1 "QC of SAS LOG(s)";
data _null_;
   retain _k 0; *Internal counter;
   file PRINT;
   set _alllogs0 end=eof;
   by _fn _ln;
   if first._fn then do;
   put // @1 '***** LOG FILE: ' _fn /;
   if index(_txt,'ERROR:') or
     index(_txt,'WARNING:') or
     then do;
      put _txt;
   if last._fn and _k=0 then
     put @1 '** NO ISSUES FOUND **';
   if eof then put / '/*EOF*/';

This macro is different from most in that it will do a whole directory of SAS LOGs , not just one file (but this can be specified in the FILE statement in the first datastep).

The aim in the final production version is to have '** NO ISSUES FOUND **' when this is found for every program, and this along with the SAS LOGs be placed in the final documentation for the TLF programming. It may not always be possible to achieve but documentation should be given explaining where it is not. If you are writing a WARNING message to the SAS LOG, write:

   'WAR' 'NING: Issue with program';

and the word ‘WARNING:’ will not be printed out to the SAS LOG unless there is an issue.

To give an example, I recently dealt with an issue where in the SAS LOG was the following message:

   WARNING: A character that could not be transcoded was encountered.

This message was produced in the SAS LOG for several runs previously but was either not found earlier, found and ignored, or found and thought to be okay. As it turned out, SAS thought the data coming in was in one format but was actually in another format resulting in the data not being read correctly from the file.

Numeric to character, and character to numeric conversions are an issue and should not be ignored

Hope this is useful. See you next month.

Updated August 2, 2014