********************************************************************; * Error detector 1.5 *; * Purpose: to read sas log files and report errors back to you *; * It scans the log first for the copyright notice and then any *; * errors generated in the log itself *; * If it only finds the copyright notice it assumes a successful *; * run. This may be false if something aborted the job immediately *; * CHANGE THE FILE YOU ARE SCANNING AT THE BOTTOM OF THE PROGRAM *; * YOU SHOULD ALSO CHANGE THE EMAIL ADDRESS IN THE MIDDLE OF THE *; ********************************************************************; * First we read the log file *; %macro errordet(filename); data temp1; infile &filename truncover; length statement $ 150; input statement $ 1-150; run; quit; *then we substring the log file for the first 15 characters *; data temp2; set temp1; errorfind=substr(statement,1,15); obsnum=_n_; run; quit; * then we scan for the words error, warning and copyright *; data temp3; set temp2; error1='ERROR'; warn1='WARNING'; copy1='Copyright'; result1=index(errorfind,error1); result2=index(errorfind,warn1); result3=index(errorfind,copy1); run; * then we throw out the statements that do not match the criteria *; data temp4; set temp3; if (result1 > 0) or (result2 > 0) or (result3 > 0); count=_n_; run; quit; * then we run a proc means against the new data to see if there is just *; * the copyright notice or more *; * if there is just the copyright notice countsum will be 1 *; * if there is more than that the countsum will be greater than 1 *; * we then turn this into a macro variable we execute conditionally *; proc means n data=temp4 noprint; var count; output out=errcount n=countsum; run; quit; data errcount; set errcount; call symput('errfind',countsum); run; %put &errfind; * then we run the mail routine that checks to see how many exist *; * if there is more than just the copyright notice we email an alert *; * otherwise we email a succesful run *; %macro mailit(email1); %if (&errfind > 1) %then %do; filename myerrors email &email1; data temp5; set temp4; if _n_ > 1; run; quit; data _null_; set temp5; file myerrors; put 'Alert !! Alert !! errors found in this run'; put &filename; put obsnum statement; run; quit; %end; %if (&errfind = 1) %then %do; filename success email &email1; data mail2; file success; put &filename; put 'ran successfully'; run; quit; %end; %mend mailit; * change the email address here *; %mailit("peter.ruzsa@sas.com"); %mend errordet; * change the file you are scanning here *; %errordet("c:\testsas\errors.log");