Please attach your code using the {i} icon. It will be easier to read and to locate errors.
Attaching a .txt file is not very friendly and less usefull.
%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 .
1) Change line:
proc printto log=log; run; /* close the log file */
into
proc printto; run; /* close the log file */
2) Checking the log:
As there is a check for strings "ERROR" and "Warning" - I hope you may have them in log, given by sas only.
I hope that will finally give you the desired output.
Thanks Shmuel for your great help and guidance. The issue is still there.
I will try with some other program.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.