BookmarkSubscribeRSS Feed
AndyJ_
Calcite | Level 5

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
;
2 REPLIES 2
JoshB
Quartz | Level 8

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=("sender@domain.com")
FROM=("recipient@domain.com")
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=("sender@domain.com")
FROM=("recipient@domain.com")
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.

MadhuKorni
Quartz | Level 8

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,";
footnote2 "YYY";

run;

ods _all_ close;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1093 views
  • 1 like
  • 3 in conversation