BookmarkSubscribeRSS Feed
DrZenith
Calcite | Level 5

Hey guys...

On googling, I found the following template to send the output in an email automatically,

%let subject = %str(Email configuration test);

%let fromEmail = '<Email Address>';

%let toEmail = '<Email Address>';

%let path = C:\documents and settings\&sysuserid.\my documents\test.htm;

FILENAME OUTPUT EMAIL

                SUBJECT = "&subject."

                FROM = &fromEmail.

                TO = &toEmail.

                CT ='text/html';

data _NULL_;

file output;

put "Working";

run;

I have a couple of SQL queries (Select queries) which I have written in PROC SQL in a SAS program, I want the output in HTML format to be sent in an email automatically. How would I change the above template or any other simpler method??

10 REPLIES 10
Peter_C
Rhodochrosite | Level 12

have a look at ATTACH E-mail option of the FILENAME statement in the doc at http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002058232.htm

FriedEgg
SAS Employee

filename eml email to='some@work.com';

proc printto print=eml;

proc sql;

select * from sashelp.class;

quit;

proc printto;

FriedEgg
SAS Employee

Missed that you wanted it in html format...

filename eml email to='someone@work.com' ct='text/html';

ods listing close;

ods html body=eml;

ods select sql_results;

ods noproctitle;

proc sql;

select * from sashelp.class;

quit;

GreggB
Pyrite | Level 9

I tried this but it looks like it delivered html code rather than output.  What do you think?

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<meta name="Generator" content="SAS Software Version 9.3, see www.sas.com">

<meta http-equiv="Content-type" content="text/html; charset=windows-1252">

<title>SAS Output</title>

<style type="text/css">

<!--

NN
Quartz | Level 8 NN
Quartz | Level 8

This is something that i tried and got a proper result

ods _all_ close;

filename message email

to="myid@mymail.com"

from = "myid@mymail.com"

subject = "test"

ct="text/html";

ods html body = message style = minimal rs=none;

proc sql;

select * from sashelp.class;

run;

ods html close;

ods listing;

FriedEgg
SAS Employee

GreggB,

This is normally the result of not setting the content type on the filename statement.

filename eml email to='someone@work.com' ct='text/html';

DrZenith
Calcite | Level 5

Thanks FriedEgg (Good name BTW:smileygrin:), it helped me a great deal, but its sending me the output (HTML format) embedded in the mail, not as an attachment. Any help on that would be great!

polingjw
Quartz | Level 8

If you are using the default MAPI email interface, you need to switch to using SMTP email in order to include HTML formatted email in the body of the message.

FriedEgg
SAS Employee

Oh, you want to send as attachment....

filename tmp temp;

%let afile=%sysfunc(pathname(tmp));

filename eml email

to='mkastin@i-behavior.com'

subject='attach something'

attach=("&afile" ct='text/html' name='procsql_results' ext='html');

ods html body=tmp;

proc sql;

  select * from sashelp.class;

quit;

ods html close;

data _null_;

file eml;

  put "It's done";

run;

murphykobe
Calcite | Level 5

Thank you very much sir, 

 

Is there possible to add a logic check only sent email if the sql return is not null? 

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!
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
  • 10 replies
  • 6597 views
  • 4 likes
  • 7 in conversation