Help using Base SAS procedures

Send results of PROC SQL in an e-mail automatically

Reply
Occasional Contributor
Posts: 12

Send results of PROC SQL in an e-mail automatically

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

Valued Guide
Posts: 2,175

Send results of PROC SQL in an e-mail automatically

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

Trusted Advisor
Posts: 1,300

Send results of PROC SQL in an e-mail automatically

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

proc printto print=eml;

proc sql;

select * from sashelp.class;

quit;

proc printto;

Trusted Advisor
Posts: 1,300

Send results of PROC SQL in an e-mail automatically

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;

Super Contributor
Posts: 268

Send results of PROC SQL in an e-mail automatically

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

<!--

Regular Contributor
Regular Contributor
Posts: 166

Re: Send results of PROC SQL in an e-mail automatically

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;

Trusted Advisor
Posts: 1,300

Send results of PROC SQL in an e-mail automatically

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';

Occasional Contributor
Posts: 12

Send results of PROC SQL in an e-mail automatically

Thanks FriedEgg (Good name BTW:smileygrinSmiley Happy, 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!

Regular Contributor
Posts: 171

Send results of PROC SQL in an e-mail automatically

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.

Trusted Advisor
Posts: 1,300

Send results of PROC SQL in an e-mail automatically

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;

Ask a Question
Discussion stats
  • 9 replies
  • 1353 views
  • 4 likes
  • 6 in conversation