BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kjohnsonm
Lapis Lazuli | Level 10

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

[…]

                    _
                    22
ERROR 22-322: Expecting a name. 
110        /*[/pre]*/
7 The SAS System                                                                                                                                                                                                               10:52 Thursday, December 27, 2018
111        /*proc print data=my_warning_log;*/
112        RUN;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
     

112      !     quit;
ERROR: Errors printed on page 6.
NOTE: SAS Institute Inc., SAS Campus Drive, Cary, NC USA 27513-2414
NOTE: The SAS System used:
      real time           1.57 seconds
      cpu time            0.84 seconds
1 ACCEPTED SOLUTION
5 REPLIES 5
kjohnsonm
Lapis Lazuli | Level 10
sorry if to verbose on a simple question, but wanted to be complete on what I am doing here...
kjohnsonm
Lapis Lazuli | Level 10

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.

😎

kjohnsonm
Lapis Lazuli | Level 10

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;

SASKiwi
PROC Star

@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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 4844 views
  • 1 like
  • 2 in conversation