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



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

Paper TT09 Using SAS to Send Bulk s With Attachments

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

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

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

XMailer Reference Guide

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

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

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

Choosing the Best Method to Create an Excel Report Romain Miralles, Clinovo, Sunnyvale, CA

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

Configuring a SAS Business Intelligence Client with the SAS Server to Support Multilingual Data Wei Zheng, SAS Institute Inc.

Integrating SAS and Excel: an Overview and Comparison of Three Methods for Using SAS to Create and Access Data in Excel

Integrating VoltDB with Hadoop

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

Creating synergy by integrating SAS and Lotus Notes

A Comprehensive Automated Data Management System Using SAS Software

From Database to your Desktop: How to almost completely automate reports in SAS, with the power of Proc SQL

You have got SASMAIL!

Improving Your Relationship with SAS Enterprise Guide

SysPatrol - Server Security Monitor

Forms Printer User Guide

Integration for Open Text Fax Appliance and Open Text Fax Appliance, Premier Edition

Technical Paper. Defining an ODBC Library in SAS 9.2 Management Console Using Microsoft Windows NT Authentication

ABSTRACT INTRODUCTION SAS AND EXCEL CAPABILITIES SAS AND EXCEL STRUCTURES

Customized Excel Output Using the Excel Libname Harry Droogendyk, Stratia Consulting Inc., Lynden, ON

McAfee Network Threat Response (NTR) 4.0

IBM FileNet eforms Designer

Analyzing the Server Log

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.

Pine Exchange mini HOWTO

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

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

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

MULTIFUNCTIONAL DIGITAL SYSTEMS. Network Fax Guide

ing a large amount of recipients

NetWrix SQL Server Change Reporter. Quick Start Guide

SQL Pass-Through and the ODBC Interface

Flat Pack Data: Converting and ZIPping SAS Data for Delivery

ServerView Inventory Manager

IceWarp Server. Log Analyzer. Version 10

Tips and Tricks SAGE ACCPAC INTELLIGENCE

How To Write A Clinical Trial In Sas

PaperClip Audit System Installation Guide

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

MAS 500 Intelligence Tips and Tricks Booklet Vol. 1

SAS ODS HTML + PROC Report = Fantastic Output Girish K. Narayandas, OptumInsight, Eden Prairie, MN

Methodologies for Converting Microsoft Excel Spreadsheets to SAS datasets

Create an Excel report using SAS : A comparison of the different techniques

Escalation Server Documentation For Tele-Support HelpDesk Rev 5/29/2001

William E Benjamin Jr, Owl Computer Consultancy, LLC

WebSpy Vantage Ultimate 2.2 Web Module Administrators Guide

Suite. How to Use GrandMaster Suite. Exporting with ODBC

Intended status: Standards Track October 8, 2014 Expires: April 11, 2015

GFI FAXmaker 14 for Exchange/Lotus/SMTP. Fax-Client Manual. By GFI Software Ltd

Creating Dynamic Web Based Reporting

Accessing Your Database with JMP 10 JMP Discovery Conference 2012 Brian Corcoran SAS Institute

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

Exchange Mailbox Protection

TECHNICAL REFERENCE GUIDE

Hands-On Workshops. HW009 Creating Dynamic Web Based Reporting Dana Rafiee, Destiny Corporation, Wethersfield, CT OVERVIEW OF SAS/INTRNET SOFTWARE

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

# or ## - how to reference SQL server temporary tables? Xiaoqiang Wang, CHERP, Pittsburgh, PA

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

DiskPulse DISK CHANGE MONITOR

INTRODUCTION: SQL SERVER ACCESS / LOGIN ACCOUNT INFO:

Table of Contents. Chapter 1: Getting Started. Chapter 2: Using Mass Mailer TABLE OF CONTENTS. About This Manual... 4

Importing Data from Microsoft Access into LISTSERV Maestro

Get in Control! Configuration Management for SAS Projects John Quarantillo, Westat, Rockville, MD

PharmaSUG 2014 Paper CC23. Need to Review or Deliver Outputs on a Rolling Basis? Just Apply the Filter! Tom Santopoli, Accenture, Berwyn, PA

Autodesk Product Manager Tool

Setting Up ALERE with Client/Server Data

SPEX for Windows Client Server Version 8.3. Pre-Requisite Document V th August 2006 SPEX CS 8.3

Create! Upgrade Notes

SAS/ACCESS 9.3 Interface to PC Files

Novell ZENworks Asset Management 7.5

Attix5 Pro Plug-ins. V6.2 User Manual. Cover. for Microsoft Windows. Your guide to installing and using Attix5 Pro plug-ins. Last updated: 2011/10

ABSTRACT INTRODUCTION IMPORTING THE DATA SESUG Paper CT-23

Administrator Operations Guide

Exploiting Key Answers from Your Data Warehouse Using SAS Enterprise Reporter Software

Rational Reporting. Module 3: IBM Rational Insight and IBM Cognos Data Manager

Installation Instructions for Version 8 (TS M1) of the SAS System for Microsoft Windows

GFI White Paper: GFI FaxMaker and HIPAA compliance

Business Intelligence Tutorial

PrivateWire Gateway Load Balancing and High Availability using Microsoft SQL Server Replication

LISTSERV LDAP Documentation

Excel with SAS and Microsoft Excel

Contents CHAPTER 1 IMail Utilities

Let SAS Modify Your Excel File Nelson Lee, Genentech, South San Francisco, CA

IceWarp to IceWarp Server Migration

Hands-On Workshops. Running SAS Applications on the Web

Database migration using Wizard, Studio and Commander. Based on migration from Oracle to PostgreSQL (Greenplum)

Data processing goes big

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

Ipswitch Client Installation Guide

W ith the ubiquity of comes the increased A BNA, INC. DIGITAL DISCOVERY & E-EVIDENCE! Exchange Message Tracking Logs Message Forensics

SAS Client-Server Development: Through Thick and Thin and Version 8

Transcription:

Paper 039-29 Automated distribution of SAS results Jacques Pagé, Les Services Conseils HARDY, Quebec, Qc ABSTRACT This paper highlights the programmable aspects of SAS results distribution using electronic mail facilities. It provides a clear understanding of all options, statements and commands for that purpose. Also provided are means for accessing data from your Outlook or Notes address books. INTRODUCTION Now that SAS (ODS) can produce publication-ready results in various formats, it is also quite convenient to use SAS in order to distribute those results via email. It is then possible to entirely automate the production and distribution of SAS results. 1

SUPPORTED STANDARDS AND MAIL ENGINES MAPI (Messaging Application Program Interface) Used by Microsoft products (Outlook) VIM (Vendor Independent Mail) Used by IBM products (Notes) SMTP (Simple Mail Transport Protocol) Provides a direct communication between SAS and your SMTP server, i.e. without passing through a mail software. These are actually considered as "SAS mail engines". CONTROL SAS email facilities are controlled by email options or commands at four different scope levels: 1. System options 2. FILENAME statement options 3. FILE statement options (DATA step) 4. PUT statement directive commands (DATA step) MAIL RELATED SYSTEM OPTIONS GENERAL -EMAILSYS MAPI VIM SMTP Determines which application interface to use (MAPI or VIM), or indicates direct communication with the SMTP server (SMTP). See figure 1 below. -EMAILID "logon id" May be requested by your email software when you specify MAPI or VIM under the EMAILSYS option. -EMAILPW "password" May be requested by your email software when you specify MAPI or VIM under the EMAILSYS option. SMTP SPECIFIC -EMAILHOST "SMTP-server-domain-name" Specifies the exact domain name for your SMTP server. Ex. "mail.schardy.qc.ca" -EMAILPORT port-number Specifies the physical port number used for SMTP communication. Generally, port 25 is used and it is the default value for this option. WHERE TO SPECIFY? All those system options are configuration or start-up options. They must be specified in the SAS configuration file (SasV8.cfg) or in the SAS start-up command. It is therefore impossible to specify those options on a regular OPTION statement. FIGURE 1 MAIL ENGINES USAGE MAPI SAS VIM OUTLOOK SMTP NOTES SMTP SERVER 2

FILENAME STATEMENT A FILENAME statement is required for sending email from a DATA or PROC step. Must precede the step that actually sends the email. Must specify the EMAIL access method. FILENAME STATEMENT SYNTAX FILENAME fileref EMAIL <"address"> <options> ; Fileref is a name by which to which DATA or Proc steps will refer to in order to send email. Address is the recipient's email address (can also be specified as an option). Options will provide normal email specifications FILENAME STATEMENT OPTIONS CC= "address" CC= ("address-1" "address-n") email address of someone to receive a copy of the email FROM= "address" author's address SUBJECT= "subject-of-the-message" ATTACH= "access path and name of an attached file" ATTACH=( "access path and name of attached file 1" "access path and name of attached file n") REPLYTO= "address" REPLYTO= ("address" "address") TO= "address" TO= ("address" "address") recipient's email address(es) CT= "text/plain" or "text/html" (with EMAILSYS=SMTP only) for Version 8 The "text/html" value of this option indicates that the body of the message is HTML formatted but does not actually format it into HTML code. EMAILID= "logon-id" EMAILPW= "password EMAILSYS= MAPI VIM SMTP These last three options are normally specified as system options from the SAS configuration file. The FILENAME statement lets us override them. FILENAME STATEMENT EXAMPLES FILENAME outmail EMAIL charlie@sas.com subject="results as of 2003-07-14"; FILENAME outmail EMAIL charlie@sas.com subject="results as of 2003-07-14" attach="c:\my Folder\pers.html"; 3

EMAILING FROM THE DATA STEP The DATA step uses the FILE statement to direct output to a mail destination specified on a previous FILENAME statement. It also uses PUT statements to actually write the contents of the message, i.e. the message body. GENERIC EXAMPLE FILENAME outmail EMAIL SUBJECT="Results as of %sysfunc(date(),yymmdd10.)" FROM= "bob@sas.com" TO= "charlie@sas.com" ATTACH= "C:\My Folder\test.html"; FILE outmail; PUT "Here are the results for your last query"; INTEGRATED EXAMPLE /* Identifying the results file */ %LET results=c:\my Folder\test.html; /* Producing the actual results (HTML format) */ ODS HTML BODY="&results" STYLE=sasweb; TITLE1 "Average of salaries by department and function"; PROC TABULATE DATA=mylib.pers; CLASS dept function; VAR salary; TABLE dept,function*mean*salary; ODS HTML CLOSE; /* Global email options */ FILENAME output EMAIL SUBJECT="Results as of %sysfunc(date(),yymmdd10.)" FROM= "bob@sas.com" TO= "charlie@sas.com" ATTACH= "&results"; /* Sending email */ FILE output; PUT "Here are the results of your last query (attached HTML file)"; 4

FILE STATEMENT FOR EMAILING FROM THE DATA STEP A FILE statement is required for emailing from the DATA step. It directs output from the PUT statement(s) to a mail destination specified on a previous FILENAME statement. FILE STATEMENT SYNTAX FILE fileref <mail options>; fileref must correspond to a fileref defined on a previous FILENAME statement mail options are optional. If used, they override corresponding mail options specified at the FILENAME level. FILE STATEMENT EXAMPLE /* Common mail options */ FILENAME outmail EMAIL SUBJECT="Results as of %sysfunc(date(),yymmdd10.)" FROM= "bob@sas.com"; FILE outmail TO= "charlie@sas.com" ATTACH="C:\My Folder\test1.html"; PUT "Here are the results of your query"; FILE outmail TO= "alice@sas.com" ATTACH="C:\\My Folder\test2.html"; PUT "Here are the results of your query"; In this example, two DATA steps are used to send different mail messages (the attached file being different) to different persons. 5

EMAILING FROM A PROC STEP (HTML OUTPUT) Through ODS, the results of any PROC step may be sent as the body of a mail message without having to use a DATA step. Currently, only HTML may be used as the ODS destination and this requires using the EMAILSYS=SMTP option. EXAMPLE /* Global email options */ FILENAME output EMAIL SUBJECT= "Sales summary report 1" FROM= "bob@sas.com" TO= "charlie@sas.com" CT= "text/html" /* Required for HTML output */ ; ODS HTML BODY=output STYLE=sasweb; TITLE JUSTIFY=left "Total Sales by Country and Product type as of %sysfunc(date(),yymmdd10.)"; PROC REPORT DATA=sashelp.prdsale NOWD STYLE(REPORT)=[PREHTML="<hr>"] /*Inserts a rule between title & body*/; COLUMNS COUNTRY PRODTYPE,ACTUAL; DEFINE COUNTRY /GROUP; DEFINE PRODTYPE /ACROSS; DEFINE ACTUAL/SUM ""; BREAK AFTER PRODTYPE /SUMMARIZE; ODS HTML CLOSE; FIGURE 2 - HTML MESSAGE AS SEEN UNDER OUTLOOK 6

DIRECTIVE COMMANDS FROM THE PUT STATEMENT Within a DATA step, the PUT statement accepts directive commands that can override some mail options specified at the FILENAME or FILE level. That facility allows dynamic modification of mail options for each iteration of the DATA step. It is therefore possible, for example, to modify the recipient's address (TO= option) according to the current value of a recipients dataset in other words implementing a mail merge application. DIRECTIVE COMMANDS SYNTAX PUT directive-command <value>; COMMON DIRECTIVE COMMANDS These commands will override the corresponding mail options specified at the FILENAME or FILE level:!em_attach!!em_cc!!em_from!!em_replyto!!em_subject!!em_replyto! SPECIAL DIRECTIVE COMMANDS These commands control the actual sending of the message and the persistence of the dynamic values.!em_send!!em_abort!!em_newmsg! When sending email thru a DATA step, an implicit!em_send! command is executed at the end of each iteration very similar to the implicit OUTPUT statement for writing the current observation into the output dataset. If the actual sending of the message has to be conditional, then an explicit!em_send! command must be executed. Contrary to the OUTPUT statement analogy however, the implicit!em_send! command will still be executed; the!em_abort! command must then be specified at the bottom of the DATA step in order to prevent implicit sending. The!EM_NEWMSG! command is used for clearing any dynamic mail option specified in the current cycle. MAIL MERGE EXAMPLE FILENAME outbox EMAIL FROM="bob@www.sas.com" SUBJECT="Analytical results as of December 12, 2003" ATTACH="C:\Statistics\stat20031212.html"; FILE outbox; /* Read recipients data */ SET contacts (KEEP= sex name email_add); PUT "!EM_TO!" add_email; IF sex = "F" THEN PUT "Mrs " name ","; ELSE IF sex = "M" THEN PUT "Mr " name ","; PUT " "; PUT "Here are the periodic analytical results for 2003-12-12"; PUT " "; PUT "The results are contained in an HTML file that can be"; PUT "opened under Excel"; 7

ACCESSING YOUR OUTLOOK OR NOTES CONTACT FILES With MAPI or VIM engines, you can use any symbolic recipient name or even group names defined in the contact files. It is however impossible to get access to other fields of recipients data (sex, title, geographic address, etc.). When SMTP engine is used, no direct access to your contact files is provided. This section will show how Outlook or Notes address books may be accessed from your DATA step. READING THE OUTLOOK CONTACT FILES No standard ODBC interface (surprisingly!) Possibility of manually exporting to a delimited file, but that task would have to be repeated in order to get fresh data. The following Vbs script extracts some meaningful data from the default contact file and exports them into a delimited file. The script is executable from a SAS program through an X statement. 'This script creates a CSV file containing one record for every 'contact within the default Outlook contact file 'Starting Outlook Set outl = CreateObject("Outlook.Application") 'Getting access to Outlook folders Set MyNameSpace = outl.getnamespace("mapi") 'Obtaining the default contact file Set Cont = MyNameSpace.GetDefaultFolder(10) 'Creating the delimited file Set fso = CreateObject("Scripting.FileSystemObject") 'Opening the file Set f = fso.opentextfile("c:\my Folder\contacts.csv", 2, True) For Each Item In Cont.Items 'Writing a record for each contact f.writeline Item.FullName & "," _ & Item.Title & "," _ & Item.Email1Address Next The following program is an example of a SAS program invoking the previous script: /* Invoking the VBS script */ OPTION NOXWAIT; X "C:\My scripts\outlook_csv.vbs" ; /* Converting the CSV file produced by the script into a SAS dataset */ DATA contacts; INFILE "C:\My Folder\contacts.csv" DLM="," DSD; LENGTH contact $ 40 title $ 3 email_add $ 100; INPUT contact title email_add; FILENAME outbox EMAIL FROM="bob@sas.com" SUBJECT="Analytical results as of December 12, 2003" ATTACH="C:\Statistics\stat20030912.html"; FILE outbox; /* Reading contacts datasets */ SET contacts (KEEP= title email_add); PUT "!EM_TO!" email_add; PUT title ","; PUT " "; PUT " Here are the results of your last query (attached HTML file)"; PUT " "; PUT "These results are contained in an HTML file that can be opened"; PUT "under Excel"; 8

READING THE NOTES ADDRESS BOOK The NOTESSQL ODBC driver, supplied by Lotus, provides access to Lotus Notes databases, including the address book database. The driver must be installed on your machine and an ODBC data source must be configured. DATA may be accessed through a LIBNAME statement or using SQL Pass-through. The following program uses SQL Pass-through in order to access a Notes address book. The ODBC data source, named "notes_book" in this example, must have been configured on your machine. PROC SQL; CONNECT TO ODBC ("DSN=notes_book"); CREATE TABLE contacts AS SELECT * FROM CONNECTION TO ODBC (SELECT * FROM address_book); DISCONNECT FROM ODBC; 9

CONCLUSION Distributing SAS results thru email is Easy Cost effective Reliable Highly programmable May All Implement Likewise! CONTACT INFORMATION Your comments and questions are valued and encouraged. Contact the author at: Jacques Pagé Les Services Conseils HARDY 4715 des Replats, bureau 260 Québec, Qc Canada G2J 1B8 Work Phone: (418) 626-1666 Fax: (418) 626-2097 Email: jpage@schardy.qc.ca Web: www.schardy.qc.ca 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. Other brand and product names are trademarks of their respective companies. 10