%let run=&sysdate;
%let SYscc=0;
filename mylog "/C:/&run._test.log";
proc printto file=mylog new;
run; /* open and start keep log */
%global ERR_LINE WARN_LINE;
data one;
input NAME $ SEX $ AGE Height WEIGHT;
datalines;
STEVE M 41 74 170
ROCKY M 42 68 166
KURT M 39 72 167
DEBORAH F 30 66 124
JACQUELI F 33 66 115
;
run;
/*added coded only to test error and warning msg*/
proc sql;
connect to oracle as EXT1 (user="&User." orapw="&OraPw." path="&Path.");
create table work.abc as
Select * from connection to EXT1
(select * from emp
);
disconnect from ext1;
quit;
%let OutPut=/C:/;
ods tagsets.excelxp FILE = "&Output/Test_&run.xls"
style=analysis
options (embedded_titles='yes'
embedded_footnotes='no'
orientation='landscape'
fittopage='yes'
missing_align='center'
autofit_height='yes'
autofilter='yes'
row_repeat='1'
sheet_name='Data'
sheet_interval='None');
proc print data= one ;
title "test Output" ;
run;
ods tagsets.excelxp close;
%let myrc = &syscc;
proc printto log=log; run; /* close the log file */
/* checking the log */
*filename msg '/proj/sastmp/pvdm/99_TEST_QC/help.txt';
data _null_;
retain count_warn 0;
infile mylog end=eov;
***file msg;
input a_line $2000; /* adapt to max log line */
if index(a_line, 'ERROR') then
call symput('ERR_LINE', trim(a_line));
if index(a_line,'Warning') then count_warn +1;
if eov then
call symput('Warn_line', cat('there are ',left(count_warn), ' warnings'));
run;
*Begin email code;
%put "&warn_line.";
%put "&err_line.";
%macro check;
%if %eval(&myrc) LE 4 %then %do;
FILENAME myemail2 EMAIL from=("abc@gmail.com")
to=("abc@gmail.com")
Subject = "SAS without any error"
Attach = ("/C:/Test_&run..xls"
"/C:/&run._test.log");
data _null_;
file myemail2;
Put "Dear X";
put " ";
put "Report with no error";
run;
%end;
%else %do;
FILENAME myemail2 EMAIL from=("abc@gmail.com")
to=("abc@gmail.com")
Subject = "SAS with error"
Attach = ("/C:/&run._test.log");
data _null_;
file myemail2;
Put "Dear X";
put "&warn_line.";
put "&err_line.";
put "Report with error.";
run;
%end;
%mend check;
%check;
Please have a look .
... View more