[last updated - 27 July 2003]
Scanning SAS logs for important messages is a very neglected thing in the QC process. Maybe this is because there is not an easy-to-use utility to do this. Well I have written one and it uses awk which you can think of as a better version of grep that is also a lot more complicated.
#!/bin/sh # Script : scanlogs # Version : 1.0 # Author : Roland Rashleigh-Berry # Date : 27 July 2003 # Contact : roland@rashleigh-berry.fsnet.co.uk # Purpose : To scan SAS logs for important warnings, notes and errors # SubScripts : none # Notes : This is an important QC tool to ensure your SAS programs have run # correctly. # Usage : scanlogs *.log # #================================================================================ # PARAMETERS: #-pos- -------------------------------description-------------------------------- # 1 logs to scan #================================================================================ # AMENDMENT HISTORY: # init --date-- mod-id ----------------------description------------------------- # #================================================================================ # This is public domain software. No guarantee as to suitability or accuracy is # given or implied. User uses this code entirely at their own risk. #================================================================================ if [ $# -lt 1 ] then echo "Usage: scanlogs *.log" 1>&2 exit 1 fi while [ $# -gt 0 ] do awk '{if ( ( index($0,"ERROR") == 1 \ || index($0,"WARNING") == 1 \ || index($0,"MERGE statement") > 0 \ || index($0,"W.D format") > 0 \ || index($0,"truncated ") > 0 \ || index($0," 0 observations and ") > 0 \ || index($0,"outside the axis range") > 0 \ || index($0,"NOTE: Invalid") == 1 \ || index($0,"uninitialized") > 0 ) \ && index($0,"Errors printed on") == 0 \ && index($0,"scheduled to expire on") == 0 \ && index($0,"product with which") == 0 \ && index($0,"representative to have") == 0 ) {printf "%-30s %-80s\n","'$1'",$0}}' $1 shift done
You should be familiar with everything that precedes the call to awk if you have studied the previous examples. For a start-off, look at all the lines that end with a "\". I mentioned before that shell interpreters expect one statement per line. But when a statement has to go over one line then you have got to use a continuation character which is the "\" that I have used. Note that for awk, testing for equality is done with a double equals symbol. "Or" is a double "|" symbol and "and" is a double "&" symbol. It is testing for important message lines but ignoring lines that are not helpful, especially licence expiry warnings. If these conditions are met the it uses the printf statement to print out formatted values. The first 30 spaces it uses for the file name it is working on and the next 80 spaces it uses for the whole line in the log file. Note that awk refers to the entire input line as $0. $1 would be the first field in that line but we don't want to display that. We DO, however, want to display the file name that is also referred to as $1. To make this distinction, note the file name is referred to as "'$1'" to indicate that it is a variable outside awk and not and internal awk variable.
Go back to the home page.
E-mail the macro and web site author.