Help using Base SAS procedures

Help concerning mail generated from SAS

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 10
Accepted Solution

Help concerning mail generated from SAS

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.


Accepted Solutions
Solution
‎12-08-2013 04:16 PM
Frequent Contributor
Posts: 87

Re: Help concerning mail generated from SAS

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


All Replies
Respected Advisor
Posts: 3,799

Re: Help concerning mail generated from SAS

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

Occasional Contributor
Posts: 10

Re: Help concerning mail generated from SAS

Posted in reply to data_null__

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?

Respected Advisor
Posts: 3,799

Re: Help concerning mail generated from SAS

The file(s) created by ODS HTML.

PROC Star
Posts: 1,322

Re: Help concerning mail generated from SAS

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.

Occasional Contributor
Posts: 10

Re: Help concerning mail generated from SAS

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:..

Respected Advisor
Posts: 3,799

Re: Help concerning mail generated from SAS

JoeBill wrote:

Well, the code works great now,..

what code?

Occasional Contributor
Posts: 10

Re: Help concerning mail generated from SAS

Posted in reply to data_null__

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

Respected Advisor
Posts: 3,799

Re: Help concerning mail generated from SAS

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;

New Contributor
Posts: 2

Re: Help concerning mail generated from SAS

Does including the following e-mail option help?

ct="text/html"


Occasional Contributor
Posts: 13

Re: Help concerning mail generated from SAS

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...

Solution
‎12-08-2013 04:16 PM
Frequent Contributor
Posts: 87

Re: Help concerning mail generated from SAS

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;

Occasional Contributor
Posts: 10

Re: Help concerning mail generated from SAS

Thanks guys!

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

Thanks again!

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 12 replies
  • 2667 views
  • 11 likes
  • 6 in conversation