11-09-2015 03:25 PM
So I have a dataset that is similar to the one below but with a few more columns. What I would like to know is if it is possible to do something similar to a foreach loop on each observation and use the observation variables to send an email. For example, if I wanted to pull from the below dataset everything over 7 and then email XXX@blah.com a message is that possible? I appreciate any assistance.
data dummy; infile datalines dlm='#'; input location & $16. count 10.; datalines; ABC# 5 DEF# 6 GHI# 8 JKL# 14 ;
11-09-2015 03:42 PM - edited 11-09-2015 03:47 PM
Depending on your environment/network, yes, this is possible.
You can check out some references to system options here, as well as the links at the bottom of that page to the other system e-mail options.
In my experience, I've only had to specify EMAILSYS , EMAILHOST, and EMAILPORT.
I only have the ability to use SMTP on my environment so I can't speak to other protocalls but if I wanted to do this it would look similar to this:
data dummy; infile datalines dlm="#"; input location & $16. count 10.; datalines; ABC# 5 DEF# 6 GHI# 8 JKL# 14 ; options emailsys = SMTP emailhost = smtp.domain.com emailport=25 nonotes nosource; FILENAME outbox EMAIL; DATA _NULL_; FILE outbox TO=("email@example.com") FROM=("firstname.lastname@example.org") SUBJECT=("Subject" ); set dummy(where=(count >7)); PUT " "; PUT location count; PUT "Any other body you would want to say in the e-mail"; RUN;
That would be the most basic listing type output in the body of the e-mail.
Alternatively, you could create a pdf, rtf, html, etc. document, and attach that to the e-mail instead of printing the data output to the body of the e-mail. You would add a path to the file you just created on the FILE statment, e.g.,
ods pdf "path-to-file.ext"; proc print data=dummy; where count > 7; run; ods pdf close; FILENAME outbox EMAIL; DATA _NULL_; FILE outbox TO=("email@example.com") FROM=("firstname.lastname@example.org") SUBJECT=("Subject" ) ATTACH=("path-to-file.ext"); PUT "Hello."; PUT " "; PUT "Please see the attachment for dummy counts greater than 7."; PUT " "; run;
These are canned examples that I've used in my environment so YMMV, but they've worked for me.
11-10-2015 07:31 AM
filename MyMail Email
from = "yyy.blah.com"
to = "xxx.blah.com"
subject = "Locations whose count is >7 "
type = "text/html";
ods html body = MyMail style=journal;
title1 "Hi All,";
title2 "Please find below Locations whose count is greate than 7";
proc report data = Dummy;
where count > 7;
footnote1 "Thanks and Regards,";
ods _all_ close;