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

Hi Guys, hope you can help with this one:

I'm generating a SAS mail, which is supposed to distribute a mail with exchange rate fluctuations to a group of receivers. However, the procedure does not "print" the data table to the mail. Somehow, the procedure genereates the mail destributes it only with a text, and afterworth creates the table, that was supposed the be part of the mail.

Can anyone help me with this?


My code can be seen below:


FILENAME outbox EMAIL "xxx@xxx.xx";

DATA _NULL_;

FILE outbox

/* Overrides value in filename statement */

to=("xxx@xxx.xx")

cc=("")

subject="return %SYSFUNC(putn(&ReportDate,DDMMYY10.)) and daily prices %SYSFUNC(putn(&LastDate_FT,DDMMYY10.))";

     

ods listing CLOSE;

ods html3 style=sasweb;

options center;

put "Daily market prices and returns";

TITLE1 "excehange rate fluctuations %SYSFUNC(putn(&LastDate_FT, DDMMYY10.))";

FOOTNOTE;

run;

proc report data=WORK.DELTAREPORTNAMES nowd;

column ReportName Delta cv1;

define ReportName / group " " format=$20. missing order=formatted;

compute ReportName;

if ReportName ne " " then hold1=ReportName;

if ReportName eq " " then ReportName=hold1;

endcomp;

define Delta / group missing noprint;

define cv1 / computed "delta(%)" missing FORMAT=COMMAX20.2;

compute cv1;

if Delta ne . then hold2=Delta;

cv1=hold2;

endcomp;

quit;

ODS HTML CLOSE;

ods listing;

RUN;


Best, Joe.

1 ACCEPTED SOLUTION

Accepted Solutions
SteveNZ
Obsidian | Level 7

Here's the code I use and it works perfectly fine in Outlook:

ods _all_ close;

filename mymail email from="YOUREMAIL@SOMEWHERE.COM"

to="RECIPIENT@SOMEWHERE.COM"

cc="CC_IF_REQUIRED@SOMEWHERE.COM"

subject="Your E-mails Title"

content_type="text/html";

ods msoffice2k file=mymail

style = sasweb ;

*proc report code below...;

proc report data = .....

run ;

ods msoffice2k close;

View solution in original post

12 REPLIES 12
data_null__
Jade | Level 19

If you want to e-mail the report created by PROC REPORT you will need to create it in a file and attach the file to the e-mail.

SAS(R) 9.4 Statements: Reference

JoeBill
Fluorite | Level 6

So there is no way to get a table in a mail generated from SAS 9.3? Of course I can generate the table in a seperate step and attach it, but for layout-purposes I would really appreciate if the table could be a part of the mail.

What if I generated the table by PROC SQL instead?

data_null__
Jade | Level 19

The file(s) created by ODS HTML.

Quentin
Super User

As you currently have it the DATA _NULL_ step sends an email when it executes, and that happens before the table is produced by your PROC REPORT step.

What you want is the table in the body of the email, correct?

One way you can do this is to run the PROC REPORT step first, and write the results to an html file.

Then in your data step which sends the email, read that file.  Soemthing like (untested):

data _null_;
  file outbox ;

  infile MyHTMLoutput ;  *may need to set lrecl;
  input ;
  put _infile_ ;
run;

Above assumes to= subject= etc are all defined in the filename statement for outbox.

I have done that before when I wanted to add text to the message. But if you want to send just the html produced by ODS, would think you could do it with something like:

ods html3 style=sasweb file=outbox;

*PROC REPORT here;

ods html3 close;

HTH,

--Q.

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
JoeBill
Fluorite | Level 6

Well, the code works great now, and in SAS it generates the HTML output as I expect. However, in Outlook the HTML output is only in plain text/HTML code, and not the table from SAS. Do any of you have an idea about, what is wrong? I do not seem to be able to find an explanation or a solution anywhere... :smileyplain:..

data_null__
Jade | Level 19

JoeBill wrote:

Well, the code works great now,..

what code?

JoeBill
Fluorite | Level 6

The code Quentin offered. However, outlook only displays the plain HTML code. Any clue of why that is?

data_null__
Jade | Level 19

This first example is from the SAS online help for the FILENAME EMAIL statement.  It sends me an HTML formatted report in the email text.

filename outbox email
  
to='me@myplace.com'
  
type='text/html'
  
subject='Temperature Conversions';
data temperatures;
   do centigrade = -40 to 100 by 10;
      fahrenheit = centigrade*
9/5+32;
     
output;
     
end;
  
run;
ods html
  
body=outbox /* Mail it! */
  
rs=none;
title 'Centigrade to Fahrenheit Conversion Table';
proc print;
  
id centigrade;
   var fahrenheit;
   run;
ods html close;
This next example I wrote to send an html as an attachment.  There are similar examples here and I think these examples cover everthing you need to know about how to e-mail using SAS.
You could expand this example to send e-mail to a list of recipients the same attachment of different using a data set as input with address and filename to attach.  If you use this you need to read the documentation on how !EM_SEND! and !EM_ABORT! interact.  In my example I did not need either but I think you will if you send mail to a list using a data set.
ods html file='~/class.html';
proc print data=sashelp.class;
   run;
ods html close;


data _null_;
   filevar =
'me@myplace.com';
  
file dummy email filevar=filevar;
   put '!em_subject! email with attachment';
  
put '!em_attach! ~/class.html';
  
put 'Please see attached report';
  
put '!em_send!';
  
put '!em_abort!';
  
run;

BuckeyeSasquatch
Calcite | Level 5

Does including the following e-mail option help?

ct="text/html"


rocky1983
Fluorite | Level 6

Hi,

I had a g8t time in exploring option of sending mail from SAS. See I wanted to send mail which had content in body and table attached to it. I first tried sending from data null then sending table content did not work. When I moved to using proc report. all i was able to do was send table but I was not able to write content first then send have table.

So I tried different approach:

I first created table and stored content in macro variable. and then under data null use html to send content...

SteveNZ
Obsidian | Level 7

Here's the code I use and it works perfectly fine in Outlook:

ods _all_ close;

filename mymail email from="YOUREMAIL@SOMEWHERE.COM"

to="RECIPIENT@SOMEWHERE.COM"

cc="CC_IF_REQUIRED@SOMEWHERE.COM"

subject="Your E-mails Title"

content_type="text/html";

ods msoffice2k file=mymail

style = sasweb ;

*proc report code below...;

proc report data = .....

run ;

ods msoffice2k close;

JoeBill
Fluorite | Level 6

Thanks guys!

Great help! It works perfectly fine now, and the HTML output is looking great in the mail!

Thanks again!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 12 replies
  • 4707 views
  • 11 likes
  • 6 in conversation