Stay Connected to Work Away from Work: A Simple Approach to Send Emails from SAS® using VBScript Paper #124-2018
Walkthrough Introduction Purpose Existing methods Approach Code Snippets Email system Conclusion
Introduction “The first rule of any technology used in a business is that automation applied to an efficient operation will magnify the efficiency” -Bill Gates A simple, efficient and reliable standalone approach of sending emails through SAS® and VBScript Builds Dynamic E-mail contents
Purpose Periodic statistical report generation Review of reports Share with cross functional teams Avoid Manual Errors Increase efficiency Automation
Existing methods SAS® supports three interface methods to send e-mail MAPI SMTP VIM Downside – Need to tweak SAS® configuration file
(Recipients, Attachments, HTML files/links) Approach Collaboration Data Objects (CDO) SMTP Server SAS Code E-MAIL (Recipients, Attachments, HTML files/links) VBSCRIPT ---------
SAS® Code Get required macro variables (&name &date &day &month &year) Create a format to represent the months of the year
Embedded VBScript file in SAS® code to generate e-mail
VBScript code Input to VBScript code may contain 3 strings: Optional flag to alter the Subject to inform recipients of an error Full path to attachment Semicolon separated list of email addresses
Step by Step Approach Specify VB arguments and build an Email object to pull the username from the network. Set MyEmail=CreateObject("CDO.Message") Set objNetwork = CreateObject("Wscript.Network") Get current date stamp for log file y = year(now) m = month(now) d = day(now) if m < 10 Then m = "0" & m end if if d < 10 Then d = "0" & d end if isoDate = y & m & d
Step by Step Approach Confirm your script is called as expected Enter email subject, attach username to the e-mail domain and specify the To, Cc and Bcc parameters
Step by Step Approach Create Body from SAS® DataSet to HTML 'MyEmail.CreateMHTMLBody "<your file path>.html" Mechanism to send messages cdoSendUsingPickup (1) cdoSendUsingPort (2) cdoSendUsingExchange (3) Port Used: MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
Step by Step Approach Once the messages have been picked up, they are sent to an SMTP server MyEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")="sendsmtp.<domain>“ Specify the SMTP port number and send the e-mail. MyEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverp ort")=25 MyEmail.Configuration.Fields.Update MyEmail.Send set MyEmail=nothing
E-mail system
Contact Information Name: Nikita Sathish Company: Seattle Genetics City/State: Bothell, Washington Phone: (425)-527-2790 Email: nsathish@seagen.com