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? 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 10 replies
  • 7109 views
  • 4 likes
  • 7 in conversation