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??
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
filename eml email to='some@work.com';
proc printto print=eml;
proc sql;
select * from sashelp.class;
quit;
proc printto;
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;
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">
<!--
This is something that i tried and got a proper result
ods _all_ close;
filename message email
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;
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';
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!
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.
Oh, you want to send as attachment....
filename tmp temp;
%let afile=%sysfunc(pathname(tmp));
filename eml email
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;
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.