I am trying to add a data table into the automatic email I sent out using SAS.
I tried the solution code mentioned in this post and it creates an html file, which can open fine in the browser.
But the email I received does not display the tables and instead, it seemed to wrote the html in the body.
Here is the code:
filename REPORT "&path\test.html";
filename SEND email to = "xxx@xxx"
subject = "test"
from = "xxx@xxx"
content_type = "text/html";
ods html file=REPORT;
proc print data=SASHELP.CLASS(obs=2); 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;
and here is part of the email I received:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="Generator" content="SAS Software Version 9.4, see www.sas.com">
<meta http-equiv="Content-type" content="text/html; charset=windows-1252">
<title>SAS Output</title>
<style type="text/css">
<!--
.activelink
{
color: #800080;
}
.aftercaption
{
background-color: #FAFBFE;
border-spacing: 0px;
color: #112277;
font-family: Arial, 'Albany AMT', Helvetica, Helv;
font-size: x-small;
font-style: normal;
font-weight: bold;
padding-top: 4pt;
}
.batch
{
background-color: #FAFBFE;
Ideally, I would want something like:
Dear xxx:
Here is the table for today:
<a table here which pull data from SAS dataset>
Thanks,
xxx
Did I miss anything in the SAS code or setting? The html file from ods was created fine and I can open it to see the table.
Thank you in advance for your help!
Please try this:
options emailsys=smtp emailid ="sender_username@mydomain.com" emailpw=<masked> emailhost=smtphost emailport=<smtp_port> ;
title1 "<Add your title here otherwise it will default to The SAS System";
proc options group=email;
run;
FILEName Mailbox EMAIL
To = ('Receiver1@domainA.com','Receiver2@domainB.com')
Subject="Your Subject"
Content_Type="text/html"
;
ODS html body=Mailbox style = noline;
ods html text = "Dear XXX," ;
ods html text = "Here is the table for today" ;
ods html text = "" ;
proc print data=SASHELP.CLASS(obs=2); run;
ods _all_ close;
title1;
Also here is the relevant SAS paper for additional flexibility: https://support.sas.com/resources/papers/proceedings/pdfs/sgf2008/038-2008.pdf
Please try this:
options emailsys=smtp emailid ="sender_username@mydomain.com" emailpw=<masked> emailhost=smtphost emailport=<smtp_port> ;
title1 "<Add your title here otherwise it will default to The SAS System";
proc options group=email;
run;
FILEName Mailbox EMAIL
To = ('Receiver1@domainA.com','Receiver2@domainB.com')
Subject="Your Subject"
Content_Type="text/html"
;
ODS html body=Mailbox style = noline;
ods html text = "Dear XXX," ;
ods html text = "Here is the table for today" ;
ods html text = "" ;
proc print data=SASHELP.CLASS(obs=2); run;
ods _all_ close;
title1;
Also here is the relevant SAS paper for additional flexibility: https://support.sas.com/resources/papers/proceedings/pdfs/sgf2008/038-2008.pdf
Thank you!! I finally was able to test it and the code works wonderful!
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.