To dynamically e-mail output from ODS in a SAS program, specify the EMAIL device on the FILENAME statement along with the e-mail address and any other of the e-mail 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 e-mail access for your site:
emailsys smtp
emailhost your.smtp_server.host
Example 1: HTML Output under All Platforms
Here is some example code that sends HTML output in the body of your e-mail. 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;
Example 2: Attachment under All Platforms Except z/OS
For ODS destinations other than HTML (for example, RTF or PDF), the output is sent as an attachment to the e-mail. 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;
Example 3: Attachment under z/OS
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. (See more z/OS tips in SAS Note 23653.)
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.
Operating System and Release Information
*
For software releases that are not yet generally available, the Fixed
Release is the software release in which the problem is planned to be
fixed.