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! 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 5632 views
  • 0 likes
  • 2 in conversation