To dynamically email output from ODS in a SAS program, specify the EMAIL device on the FILENAME statement along with the email address and any other of the email options that you would like.
In addition, specify the following options either at invocation or in the config file. For your.smtp_server.host, substitute the Simple Mail Transport Protocol (SMTP) server that supports email access for your site:
emailsys smtp
emailhost your.smtp_server.host
Here is some example code that sends HTML output in the body of your email. Note that you must specify TYPE=TEXT/HTML, because the default content-type is TEXT/PLAIN, which would send your output as a text file with the HTML tags as text.
filename temp email to="sasctp@tcp.com"
subject="testing the email interface"
type="text/html";
ods html body=temp;
proc print data=sashelp.class;
run;
ods html close;
For ODS destinations other than HTML (for example, RTF or PDF), the output is sent as an attachment to the email. The following example code works for RTF output under all platforms except z/OS. (See example 3 for z/OS.)
Notice that the example code specifies a content-type of APPLICATION/MSWORD. For PDF, specify APPLICATION/PDF. Under Windows platforms, file types are usually registered and you can omit the content type.
ods rtf body='c:\test\temp.rtf';
proc print data=sashelp.class;
run;
ods rtf close;
filename doemail email 'person@company.com'
subject='Testing attach of html'
attach='c:\test\temp.rtf' ct="application/msword" ;
data _null_;
file doemail;
put 'this is a test';
run;
See the brief introduction to example 2. The syntax varies slightly under z/OS: use parentheses around the value for ATTACH=, and include the EXT= argument.
ods rtf body='sasxxx.sas.rtf';
proc print data=sashelp.class;
run;
ods rtf close;
filename doemail email 'person@company.com'
subject='Testing attach of html'
attach=('sasxxx.sas.rtf' ct="application/msword" ext="rtf");
data _null_;
file doemail;
put 'this is a test';
run;
For more information, see the Universal Printing topics in SAS Language Reference: Concepts in the SAS online documentation. See also the Universal Printing topics on the Base SAS focus area.