Hello SAS world,
I am using a Windows copy of SAS and the default win10 scheduler I call a simple *.bat it kicks off my SAS primary 'complicated' program, and a simple SAS log checker program both.
I have a SAS batch job that runs normally cleanly however from time to time the required resources are not available and the task fails, I trap the log and printout both from my primary program. I wanted to add a second small program that gets the log file from the first program and filters it for errors and warnings etc. into datasets, then still want to send these resulting error warning & header log data sets via email. The described creation of datasets of errors and warnings are working nicely.
What I seem to be stuck on is I cannot figure out how to then send the errors to my email? Can someone either show me a very clear example* with lots of documentation or fix this code? I can send a hello world email with a subject, it even takes macro variable and resolves it.
*(a link is okay, what I have seen so far is not helping)
options emailsys=smtp emailhost=smtp.my_domain.com emailport=25;
proc options group=email;
run;
FILENAME Mailbox2 EMAIL my_email@my_domain.com'
Subject="Show Warnings SAS batch program processed, on: &my_date1., working on errors, for &my_program. program.";
DATA _NULL_;
/* my work is just the top 25 lines of the log file, the other two are results of the log file filtered with 'index' for ERROR: and WARNING respectfully */
/*my data set names: my_warning_log my_error_log My_work;*/
/* I tired proc print on a suggestion, that has not worked so far for me */
/*proc print data=My_work;*/
/*run;*/
FILE Mailbox2;
set my_error_log;
/* I have read about this put _all but I am getting no where with it... */
/*[pre]*/
put _all_=;
/*[/pre]*/
/*proc print data=my_warning_log;*/
/*RUN;*/
RUN;quit;
...ultimately I would like to just send all three datasets in one email but cannot figure out the first one.
but I guess that is just a stack away... TIA 😎
error:
[…]
99 FILENAME Mailbox2 EMAIL 'my_email@my_domain.com'
SYMBOLGEN: Macro variable MY_DATE1 resolves to 2018-12-27_10-52-28
[…]
thank you,
I actually saw this one but did not attempt only because I really did not care about formatting it into html*. Is that required for the smtp to encode a SAS dataset? if needed I can try it out...
*it seems a little overly complicated for what I wanted.
😎
Sorry that solution was a great one. I did not read far enough down the thread, I did not read past all that table formatting code... This is all the new code I need to make mine work... thank you.
PS My error data set should normally be very small, a top 10 or top 100 might be a good circuit break so you do not get massive emails that are not helpful when things go very wrong with your code. just an added two cents.
8] -KJ
%let my_temp=%sysfunc(pathname(work))\;
%put &my_temp.;
filename REPORT "%sysfunc(pathname(work))\test.html";
filename SEND email to = "my_email@my_domain.com"
subject = "new testing"
from = "my_email@my_domain.com"
content_type = "text/html";
ods html file=REPORT;
proc print data=my_warning_log; run;
ods html close;
data _null_;
infile REPORT;
file SEND;
input;
if _infile_ ne '</html>' then put _infile_;
else do;
put '<p>More text</p></html>';
end;
run;
@kjohnsonm - great, good to see it helps. The output doesn't have to be HTML. An alternative would be RTF (Rich Text) which most email apps can handle. Setting a limit on the number of errors to email is a good idea.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.