BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
coladuck
Fluorite | Level 6

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! 

1 ACCEPTED SOLUTION

Accepted Solutions
IChatterji
Fluorite | Level 6

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 

View solution in original post

2 REPLIES 2
IChatterji
Fluorite | Level 6

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 

coladuck
Fluorite | Level 6

Thank you!! I finally was able to test it and the code works wonderful! 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

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
  • 7281 views
  • 0 likes
  • 2 in conversation