of the Month
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 to="TheBigBoss@company.com" cc=("DepartmentAManager@company.com" "DepartmentBManager@company.com") bcc="MySelf@company.com" subject="Monthly Timesheet Report for June 2011" attach = "c:\Timesheet\MonthlyReport_201106Jun.rtf"; put 'Dear All'; put; put 'Attached is the Monthly Timesheet Report for June 2011.'; put; put 'MySelf and I,'; put 'Timesheet Administrator'; run;
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