Hi, I need some help, I am building a code that extract errors from sas log and send it out by email, by now the program is working good but I need to do some adjustments. The first one is that I need to have the log both in sas program and in the external file, I put the code below but when I send the log back to the default location the external file return in blank. PROC PRINTTO LOG="/sasdata/user_Data/log.log" NEW;
RUN;
PROC PRINTTO; /*Routing back the log the default location*/
RUN; The second approach is how could I do for just to send the email when an error is found: filename mylog "/sasdata/user_Data/log.log";
filename report "/sasdata/user_Data/reportlog.txt" ;
data _null_;
infile mylog;
input;
lineno+1;
file report;
rec = _infile_;
foundit = index(rec,"ERROR:");
if ( foundit > 0 ) then do;
put lineno " " rec;
end;
foundit = index(rec,"ERROR ");
if ( foundit > 0 ) then do;
rec=substr(rec,foundit);
if length(rec) > 15 then do;
tempstr=substr(rec,1,15);
if (substr(tempstr,7,1) >= "0" and substr(tempstr,7,1) <= "9"
and index(tempstr,"-") > 0 and index(tempstr,":") > 0 ) then do;
put lineno " " rec;
end;
end;
end;
foundit = index(rec,"WARNING:");
if ( foundit > 0 ) then do;
put lineno " " rec;
end;
foundit = index(rec,"WARNING ");
if ( foundit > 0 ) then do;
rec=substr(rec,foundit);
if length(rec) > 15 then do;
tempstr=substr(rec,1,15);
if (substr(tempstr,9,1) >= "0" and substr(tempstr,9,1) <= "9"
and index(tempstr,"-") > 0 and index(tempstr,":") > 0 ) then do;
put lineno " " rec;
end;
end;
end;
foundit = index(rec,"ERROR [");
if ( foundit > 0 ) then do;
put lineno " " rec;
end;
foundit = index(rec,"WARN [");
if ( foundit > 0 ) then do;
put lineno " " rec;
end;
run;
/*SEND E-MAIL*/
filename outbox email attach=("/sasdata/u24807_Data/reportlog.txt")
to='chrodriguez@'
type='text/html'
subject= "Log ETL"
from='example@';
DATA _NULL_;
FILE outbox;
PUT "<body>";
PUT "<p>Hello, </p>";
PUT "<p>Program executed with errors.</p>";
PUT "<p>Regards.</p>";
PUT "</body>";
RUN; Any help will be pretty appreciated.
... View more