Return to Homepage

Goto the Tip of the Month Archive

Other interesting pages ...
LinkedIn Profile
SAS Cheat Sheet
Useful SAS Code
Full SAS Example
Basic Statistics
Contact Information

SAS Tip of the Month
July 2011
(for SAS and WPS)

If you run a program to produce a report on a regular basis it is sometimes useful to automate the delivery of the report in an email using SAS. Below is an example where a program is run that produces a report and then sends the report that is generated as an email to those in the To:, CC: and BCC: fields:

   *SAS Code to produce the report;

   *Close RTF file destination;
   ods rtf close;

   *Send report in email;
   filename outmsg email;
   data _null_;
      file outmsg
         cc=("" "")
         subject="Monthly Timesheet Report for June 2011"
         attach = "c:\Timesheet\MonthlyReport_201106Jun.rtf";
      put 'Dear All';
      put 'Attached is the Monthly Timesheet Report for June 2011.';
      put 'MySelf and I,';
      put 'Timesheet Administrator';

In the example the email is sent to the addresses in the To:, CC: and BCC: fields (make a copy to myself to make sure that the email was sent and keep a copy of the email for reference purposes) with the subject "Monthly Timesheet Report for June 2011", attaching the report using the attach= option.

It is possible to add some conditional code before the FILENAME statement so that if an ERROR is detected prior to the emailing step, the email is not sent, but this code is for another day.

The example shows a "hardcoded" style but the program will in reality have the month and year values in the Subject and text of the message, and the filename will also be generated from these values.

Hope this is useful. See you in August.

Updated July 5, 2011