Paper TT09 Using SAS to Send Bulk Emails With Attachments



Similar documents
Sending s in SAS to Facilitate Clinical Trial Frank Fan, Clinovo, Sunnyvale, CA

SENDING S IN SAS TO FACILITATE CLINICAL TRIAL. Frank Fan, Clinovo, Sunnyvale CA

Automated distribution of SAS results Jacques Pagé, Les Services Conseils HARDY, Quebec, Qc

SAS and Electronic Mail: Send faster, and DEFINITELY more efficiently

FIRST STEP - ADDITIONS TO THE CONFIGURATIONS FILE (CONFIG FILE) SECOND STEP Creating the to send

Using DDE and SAS/Macro for Automated Excel Report Consolidation and Generation

Optimizing System Performance by Monitoring UNIX Server with SAS

SUGI 29 Coders' Corner

PharmaSUG Paper AD11

Using Pharmacovigilance Reporting System to Generate Ad-hoc Reports

You have got SASMAIL!

Automation of Large SAS Processes with and Text Message Notification Seva Kumar, JPMorgan Chase, Seattle, WA

We begin by defining a few user-supplied parameters, to make the code transferable between various projects.

An macro: Exploring metadata EG and user credentials in Linux to automate notifications Jason Baucom, Ateb Inc.

A Method for Cleaning Clinical Trial Analysis Data Sets

A Macro to Create Data Definition Documents

Essential Project Management Reports in Clinical Development Nalin Tikoo, BioMarin Pharmaceutical Inc., Novato, CA

Using SAS With a SQL Server Database. M. Rita Thissen, Yan Chen Tang, Elizabeth Heath RTI International, RTP, NC

Importing Excel Files Into SAS Using DDE Curtis A. Smith, Defense Contract Audit Agency, La Mirada, CA

ABSTRACT THE ISSUE AT HAND THE RECIPE FOR BUILDING THE SYSTEM THE TEAM REQUIREMENTS. Paper DM

Overview. NT Event Log. CHAPTER 8 Enhancements for SAS Users under Windows NT

SUGI 29 Applications Development

THE POWER OF PROC FORMAT

SAS UNIX-Space Analyzer A handy tool for UNIX SAS Administrators Airaha Chelvakkanthan Manickam, Cognizant Technology Solutions, Teaneck, NJ

ABSTRACT INTRODUCTION FILE IMPORT WIZARD

A Comprehensive Automated Data Management System Using SAS Software

Applications Development ABSTRACT PROGRAM DESIGN INTRODUCTION SAS FEATURES USED

Using Macros to Automate SAS Processing Kari Richardson, SAS Institute, Cary, NC Eric Rossland, SAS Institute, Dallas, TX

Creating synergy by integrating SAS and Lotus Notes

One problem > Multiple solutions; various ways of removing duplicates from dataset using SAS Jaya Dhillon, Louisiana State University

Forms Printer User Guide

Automating SAS Macros: Run SAS Code when the Data is Available and a Target Date Reached.

Make it SASsy: Using SAS to Generate Personalized, Stylized, and Automated Lisa Walter, Cardinal Health, Dublin, OH

SSN validation Virtually at no cost Milorad Stojanovic RTI International Education Surveys Division RTP, North Carolina

OS/390 SAS/MXG Computer Performance Reports in HTML Format

An Approach to Creating Archives That Minimizes Storage Requirements

Mobile Business Applications: Delivering SAS Dashboards To Mobile Devices via MMS

Utilizing SAS for Complete Report Automation Brent D. Westra, Mayo Clinic, Rochester, MN

Tales from the Help Desk 3: More Solutions for Simple SAS Mistakes Bruce Gilsen, Federal Reserve Board

How To Write A Clinical Trial In Sas

DBF Chapter. Note to UNIX and OS/390 Users. Import/Export Facility CHAPTER 7

The Essentials of Finding the Distinct, Unique, and Duplicate Values in Your Data

Creating External Files Using SAS Software

GFI LANguard 9.0 ReportPack. Manual. By GFI Software Ltd.

SAS, Excel, and the Intranet

It s not the Yellow Brick Road but the SAS PC FILES SERVER will take you Down the LIBNAME PATH= to Using the 64-Bit Excel Workbooks.

GFI LANguard 9.0 ReportPack. Manual. By GFI Software Ltd.

Exclaimer Mail Archiver User Manual

SQL Case Expression: An Alternative to DATA Step IF/THEN Statements

SUGI 29 Data Presentation

Importing Excel File using Microsoft Access in SAS Ajay Gupta, PPD Inc, Morrisville, NC

REx: An Automated System for Extracting Clinical Trial Data from Oracle to SAS

Monitoring MSDynamix CRM 2011

Post Processing Macro in Clinical Data Reporting Niraj J. Pandya

ABSTRACT INTRODUCTION %CODE MACRO DEFINITION

Bag it, Tag it & Put it: Project tracking one click away!

Tips for Constructing a Data Warehouse Part 2 Curtis A. Smith, Defense Contract Audit Agency, La Mirada, CA

Remove Voided Claims for Insurance Data Qiling Shi

Dup, Dedup, DUPOUT - New in PROC SORT Heidi Markovitz, Federal Reserve Board of Governors, Washington, DC

Interfacing SAS Software, Excel, and the Intranet without SAS/Intrnet TM Software or SAS Software for the Personal Computer

THE INTRICATE ORGANIZATION AND MANAGEMENT OF CLINICAL RESEARCH LABORATORY SAMPLES USING SAS/AF"

SQL Server Automated Administration

- Training. Getting Started with Outlook Information Technology Services - Training The University of Texas at Austin

Real-Time Market Monitoring using SAS BI Tools

Data Presentation. Paper Using SAS Macros to Create Automated Excel Reports Containing Tables, Charts and Graphs

B) Mean Function: This function returns the arithmetic mean (average) and ignores the missing value. E.G: Var=MEAN (var1, var2, var3 varn);

1 Introduction 2 Installation 3 Getting Started: Default Reports 4 Custom Reports 5 Scheduling Reports

Building Your Own Real-Time SAS Server Monitor under Unix Houliang Li, Frederick, MD

Introduction to Criteria-based Deduplication of Records, continued SESUG 2012

Course Syllabus. Maintaining a Microsoft SQL Server 2005 Database. At Course Completion

Specific Information for installation and use of the database Report Tool used with FTSW100 software.

A robust and flexible approach to automating SAS jobs under Unix Mike Atkinson, with the Ministry of Health Services, British Columbia

ABSTRACT TECHNICAL DESIGN INTRODUCTION FUNCTIONAL DESIGN

While You Were Sleeping - Scheduling SAS Jobs to Run Automatically Faron Kincheloe, Baylor University, Waco, TX

ing Automated Notification of Errors in a Batch SAS Program Julie Kilburn, City of Hope, Duarte, CA Rebecca Ottesen, City of Hope, Duarte, CA

Solar Eclipse Trackers, Logs and Queues. Release 8.7.2

Effective Use of SAS/CONNECT ~ Cheryl Garner SAS Institute Inc., Cary, NC

SAS Macros as File Management Utility Programs

LinkPoint Connect for Microsoft CRM

SAS Drug Development Release Notes 35DRG07

Microsoft. Course 20463C: Implementing a Data Warehouse with Microsoft SQL Server

SAS PROGRAM EFFICIENCY FOR BEGINNERS. Bruce Gilsen, Federal Reserve Board

Order from Chaos: Using the Power of SAS to Transform Audit Trail Data Yun Mai, Susan Myers, Nanthini Ganapathi, Vorapranee Wickelgren

Exchange Brick-level Backup and Restore

Create Your Customized Case Report Form (CRF) Tracking System Tikiri Karunasundera, Medpace Inc., Cincinnati, Ohio

SAS Data Views: A Virtual View of Data John C. Boling, SAS Institute Inc., Cary, NC

SAS Hints. data _null_; infile testit pad missover lrecl=3; input answer $3.; put answer=; run; May 30, 2008

2.0. Personal Microsoft Outlook Migration Applet Guide. One-Stop Solutions for GroupWise ADVANSYS FORMATIV EXPRESS. Version

Vector HelpDesk - Administrator s Guide

This Deployment Guide is intended for administrators in charge of planning, implementing and

Efficient Techniques and Tips in Handling Large Datasets Shilong Kuang, Kelley Blue Book Inc., Irvine, CA

MacroPhone. ISDN Call Monitor, Telephone Answering Machine and Fax-Functions over Networks

Introduction to SAS Business Intelligence/Enterprise Guide Alex Dmitrienko, Ph.D., Eli Lilly and Company, Indianapolis, IN

Administering Microsoft Exchange Server ; 5 Days, Instructor-led

Dove User Guide Copyright Virgil Trasca

Producing Listings and Reports Using SAS and Crystal Reports Krishna (Balakrishna) Dandamudi, PharmaNet - SPS, Kennett Square, PA

DiskPulse DISK CHANGE MONITOR

Perfecting Report Output to RTF Steven Feder, Federal Reserve Board, Washington, D.C.

Effective Use of SQL in SAS Programming

Transcription:

Paper TT09 Using SAS to Send Bulk Emails With Attachments Wenjie Wang, Pro Unlimited, Bridgewater, NJ Simon Lin, Merck Research Labs, Merck & Co., Inc., Rahway, NJ ABSTRACT In the business world, using emails to communicate is a common practice, and more and more business communication relies on e-mails. When you need to communicate your analysis results or data checking findings to numerous recipients on a regular basis, sending bulk e-mails could be a daunting task. With the SAS DATA step combined with SAS EMAIL Access Method, sending bulk e-mails becomes a breeze. This paper presents an easy and automated approach to send out bulk e-mails with attachments on a scheduled basis (e.g. Weekly, Monthly, etc) using SAS EMAIL Access Method. SAS configuration and SAS programs will be discussed for the use of this capability. A hypothetical example on how to utilize the EMAIL Access Method will be presented with detailed step-by-step procedures. The scripts can be modified as necessary to fit your business needs and some discussions on generalizing the script will be explored. This paper is targeted at an intermediate and advanced audience. SAS Version 8.2 or 9.1, Windows XP, Intermediate or Advanced Level Key Words: SAS, DATA step, FILENAME statement, EMAIL Access Method. INTRODUCTION Sending out bulk e-mails with attachments to multiple recipients on a regular basis from e-mail software such as Microsoft Outlook is not an easy task and it is error-prone, since you could easily attached the wrong file to a wrong recipient. With SAS s EMAIL Access Method of FILENAME statement, you can automate the task with careful planning and simple implementation of SAS code. SAS EMAIL ACCESS METHOD BASICS In order to use the EMAIL access method, certain system options need to be configured. The following is the list of Email related system options: EMAILSYS, EMAILHOST, EMAILPORT, EMAILID, and EMAILPW. The following are values that are supported by EMAIL Access Method for system option EMAILSYS: MAPI: Messaging Application Program Interface (interface supported by Windows and Windows NT, which is used by Microsoft Exchange. MAPI is the default.)

VIM: Vendor Independent Mail such as Lotus or cc:mail. You can issue the following statement to find out the value for your system: proc options option=emailsys; The log: 6912 proc options option=emailsys; 6913 SAS (r) Proprietary Software Release 8.2 TS2M0 EMAILSYS=MAPI Used by E-mail Access Method and Send menu item to set the interface type with underlying e-mail system. NOTE: PROCEDURE OPTIONS used: real time 0.01 seconds cpu time 0.01 seconds Once you find out that your system supports the Email Access Method, then you can send out e-mails from within a SAS session. To configure your system to send out email automatically without being prompted, you can add the following to the SAS configuration file of SASV8.CFG or SASV9.CFG: -EMALSYS EMAILSYS VALUE -EMAILID EMAILID VALUE -EMAILPW YOURPASSWORD The following are some concrete examples of what goes into the configuration file for different EMAIL system: For Microsoft Outlook: -EMAILSYS MAPI -EMAILID Wenjie.wang@sanofi-aventis.com -EMAILPW emailpassword For Lotus Notes: -EMAILSYS VIM -EMAILID "Stacy Li/X/PH/Novartis" -EMAILPW emailpassword SYNTAX: FILENAME fileref EMAIL 'address' <email-options>; where:

fileref is a valid fileref. EMAIL is the device-type keyword that indicates that you want to use e-mail. 'address' is the valid destination e-mail address of the user you want to send mail to. You can specify 'nul' here, and then specify the destination addresses in the emailoptions. email-options are options that specify the recipients email address, subject, and cc recipients email address and attachment files, also the email system related option such as EMAILSYS, EMALID and EMALPW can be specified in here instead of SAS configuration file. You can also specify the email-options in the FILE statement inside the DATA step. Options that you specify in the FILE statement override any corresponding options that you specified in the FILENAME statement. In your DATA step, after using the FILE statement to define your e-mail fileref as the output destination, use PUT statements to define the body of the message. In your PUT statement, you use directives to specify the message attributes. The following is the list of directives that will change your message attributes:!em_to! addresses!em_cc! addresses!em_subject! Subject!EM_ATTACH! filename.ext Here are the directives that perform actions:!em_send!: sends the message with the current attributes!em_abort!: aborts the current message.!em_newmsg!: clears all attributes of the current message that were set using PUT statement directives. EXAMPLES 1. This is an example to send out a very simple message with an attachment file using FILENAME options to show the usage: filename outmail email "wenjie_wang@merck.com" subject="sales Report.doc" cc="simon_lin@merck.com" attach="c:\reports\sales Report.doc"; data _null_; file outmail; put 'Dear team,'; put 'Attached is the sales report for last quarter.';

put 'If you have any question, please feel free to call'; put 'Regards,'; put 'Wenjie'; Here is the log: 6934 filename outmail email "wenjie_wang@merck.com" 6935 subject="sales Report.doc" 6936 cc="simon_lin@merck.com" 6937 attach="c:\reports\sales Report.doc"; 6938 data _null_; 6939 file outmail; 6940 put 'Dear team,'; 6941 put 'Attached is the sales report for last quarter.'; 6942 put 'If you have any question, please feel free to call'; 6943 6944 6945 6946 6947 6948 put 'Regards,'; 6949 6950 6951 6952 put 'Wenjie'; 6953 NOTE: The file OUTMAIL is: E-Mail Access Device Message sent To: wenjie_wang@merck.com Cc: simon_lin@merck.com Subject: Sales Report.doc Attachments: c:\reports\sales Report.doc NOTE: 13 records were written to the file OUTMAIL. The minimum record length was 0. The maximum record length was 50. NOTE: DATA statement used: real time 3.13 seconds cpu time 0.16 seconds The following is the screen shot from Outlook:

2. Another example will show that you can use email options in FILE statement to override the options in FILENAME statement. filename outmail email "simon_lin@merck.com"; data _null_; file outmail to="wenjie_wang@merck.com" subject="sales Report" attach="c:\reports\sales Report.doc"; put 'Dear team,'; put 'Attached is the sales report for last quarter.'; put 'If you have any question, please feel free to call'; put 'Regards,'; put 'Wenjie';

Now the following screen shot showed that the option in FILE statement overrode the option in FILENAME statement. 3. A third example will show you how to use the directives in PUT statement: filename outmail email ; data _null_; file outmail; PUT '!EM_TO! wenjie_wang@merck.com'; PUT '!EM_SUBJECT! Sales Report '; PUT '!EM_CC! simon_lin@merck.com'; PUT '!EM_ATTACH! c:\reports\sales Report.doc'; put 'Dear team,'; put 'Attached is the sales report for last quarter.'; put 'If you have any question, please feel free to call'; put 'Regards,';

put 'Wenjie'; Here is the screen shot: SAS EMAIL ACCESS METHOD APPLICATION Now that we understand the Email Access Method basics, we can put them into good use. Think about it, if we only want send one or more files to multiple recipients, we might just do it through Outlook, but situation arises when we need to send out different file to different people based on some results on regular basis, doing so through Outlook is a pain and it is easy to attach the wrong file to the wrong person. With SAS Email Access Method and careful planning, we can automate the whole process. Let s use a hypothetical example. In a hospital, there are SOPs regarding Residents Notes Writing, which regulates that each attending resident physician needs to write a note for each admission with 24 hours; the notes could be written by his/her assistant or nurse. If he/she didn t write notes within 24 hours for certain admission(s) during the week, at the end of week, he/she will get an email with an attachment which shows the admission case with lack of the notes or delayed notes. We can automate the whole

process as the e-management tool to increase the SOP compliance rate. We will use macros to accomplish these. In this hospital, the Data Management Department stores the notes file written by doctors and nurses, and patient admission files in Mainframe. The macro will have two parameters called FROM and TO, which denote the report period span, to extract data for the report period. The notes file will have the doctors or nurses employee identification number(ein), notes written time in the form of DDMONYYYY:HH:MM:SS, Admission CaseID, Patient ID and Patient Name; The admission file will have the Attending Physician s EIN, Admission CaseID, admission date and time in the form of DDMONYYYY:HH:MM:SS, and patient name, ward and room and bed information. A permanent dataset called EMP contains all employees information, such as EIN(Employee Identification Number), first name, last name, hire date, email address, phone number, etc. The following macro shows the step-by-step implementation: %macro notes_report(from=, to=); %let today=%sysfunc(today(),date9.); /* capture report running date*/ %let from=%upcase(&from); %let to=%upcase(&to); %* Step 1: get the admission file and notes file *; filename admis "\\datam\admission\alladmission.dat"; data admission; informat admission_ dt datetime20.; infile admis LRECL=1024 pad missover; input @31 admission_dt @ ; if "&from"d < = datepart(admiss ion_dt) <="&to"d then do; input @1 adm_ein 1-10 @11 adm_caseid 11-20 @44 ward $ 44-51 @52 room_bed $ 52-61 @78 patientid 78-89 @90 PatientName $ 90-107; end; filename notefile "\\datam\notes\allnotes.dat"; data notes; informat notes_dt datetime20.; infile notefile LRECL=1024 pad missover; input @ 31 notes_dt @; if "&from"d <= datepart(notes_dt) <="&to"d+1 then do; input @1 notes_ein 1-10 @11 adm_caseid 11-20 @78 patientid 78-89 @90 PatientName $ 90-107; end;

%* Step 2: merge the two files to get the admission case which lack *; %* notes or has delayed notes *; %* for each admission, there should have a note associated with it *; proc sort data=admission; by adm_caseid; proc sort data=notes; by adm_caseid; %* merge admission and notes to find the interval between the *; %* admission time and notes time, derive the value for variables: *; %* COMPLIANCE, NOTES, and DELAY *; data allnotes; merge admission(in=a) notes(in=b drop=patientid patientname); by adm_caseid; if a; if intck('hour',admission_dt, notes_dt)>24 then do; notes=1; compliance=0; delay=1; end; else if intck('hour',admission_dt, notes_dt)=. then do; notes=0; compliance=0; delay=.; end; else if.< intck('hour',admission_dt, notes_dt) <=24 then do; notes=1; compliance=1; delay=0; end; format admission_dt notes_dt datetime20.; %* subset the non compliance records *; data noncompli; set allnotes; where delay ne 0; %* Step 3: create a macro to generate a rtf file for each attending *; %* physician who did not write a notes or who had delayed *; %* notes, and in the mean time, populate the *; %* noncompli_email_list table for sending out email later on*;

proc format; value delayf 1="Delayed Notes".="No Notes"; %macro update_noncompli_email_list( ein=, physician_name=, name=, email_address=); filename nocompli "c:\resident supervision\non compliance \Admission_Audit_Report_for_&physician_name._Wkof&to..rtf"; ods listing close; ods rtf file=nocompli bodytitle; title1 "Admission Audit Report For the Week ending at &to. for &name"; title2 "The following is a list of admission which has no notes or delayed notes as of &today"; proc sql; select admission_dt label='admission Date/Time', patientid label='patient ID', patientname label='patient Name', ward label='ward', room_bed label='room and Bed', delay label='reason' format=delayf. from noncompli where adm_ein=&ein; quit; ods rtf close; ods listing; title; %*** Now populate the noncompli_email_list table ***; proc sql; insert into noncompli_email_list values (&ein, "&name", "&email_address", "c:\resident supervision\non compliance\admission_audit_ Report_for_&physician_name._Wkof&to..rtf"); quit; %mend update_noncompli_email_list; %* Step 4: find out how many physician is not in compliance *; proc sort data=noncompli out=ein_list(keep=adm_ein rename=(adm_ein=ein)) nodupkey; by adm_ein;

proc sort data=data_a.emp out=emp; by ein; data noncompli_ein; merge emp(in=a) ein_list(in=b); by ein; if a and b; %* Step 5:Execute the macro %update_noncompli_email_list to populate*; %* dataset non_compli_email_list used for bulk email sending*; proc sql; drop table noncompli_email_list; create table noncompli_email_list (ein num, emp_name char(60), email_address char(60), attach_file char(200) ); quit; data _null_; set noncompli_ein; call execute('%update_noncompli_email_list(ein=' ein ', Physician_name=' compress(firstname) '_' compress(lastname) ', name=' compress(firstname) ' ' compress(lastname) ', email_address=' compress(email_address) ')'); %* Step 6: Send email to each non-compliant physician with the *; %* corresponding attachment *; filename myemail email; data _null_; set noncompli_email_list; file myemail; put '!EM_TO!' email_address; put '!EM_SUBJECT! Admission Audit Report for ' emp_name; put "Dear Provider " emp_name ":" ;

put ; put ; put "According to the medical record, you are either the "; put "inpatient attending physician or the attending in "; put "charge of the ward for the patient(s) listed in the "; put "attached file. "; put "An attending admission note is required by policy "; put "within one calendar day from the time of admission, "; put "but could not be found for the patient(s) listed. "; put "Please place your attending note in system ASAP. "; put "If I am mistaken in contacting you, or the data "; put "included are incorrect in any way, "; put "please contact me by email so that I can fix "; put "the problem immediately. "; put "Thank you for your attention. "; put '!EM_ATTACH! ' attach_file; put '!EM_SEND!'; put '!EM_NEWMSG!'; put '!EM_ABORT!'; %mend notes_report; To generate weekly report, just pass in the parameter value for from date and to date in the format of DATE9, this macro will do the rest. To further automate the procedure, you can put it in the Window s scheduler or use cron job in UNIX. CONCLUSION SAS Email Access Method combined with the powerful language of SAS can turn a lengthy repetitive administrative task into a quick and error-proof job. The macro demonstrated above was developed for specific business need, but it is very flexible to modify and easy to implement to fit your business need. REFFERENCES http://v8doc.sas.com/sashtml/ ---Base SAS Software ---Host Specific Information ---OS/2 Environment (Companion) --- Using Groupware to Distribute SAS Data

ACKNOWLEGEMENTS The authors would like to thank our management team for their encouragement and review of this paper. CONTACT INFORMATION Your comments and questions are valued and encouraged. Contact the authors at: Wenjie Wang Pro Unlimited Bridgwater, NJ 08807 (908) 304-6217 Wenjie.wang@sanofi-aventis.com Simon Lin Merck & Co., Inc. RY34-A320 P.O. Box 2000 Rahway, NJ 07065 (732) 594-0773 Simon_lin@merck.com TRADEMARKS SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. indicates USA registration.