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



Similar documents
Real-Time Market Monitoring using SAS BI Tools

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

Using Pharmacovigilance Reporting System to Generate Ad-hoc Reports

You have got SASMAIL!

Leveraging the SAS Open Metadata Architecture Ray Helm & Yolanda Howard, University of Kansas, Lawrence, KS

A Method for Cleaning Clinical Trial Analysis Data Sets

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

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

SAS, Excel, and the Intranet

PharmaSUG Paper AD11

IT Service Level Management 2.1 User s Guide SAS

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

SUGI 29 Coders' Corner

SUGI 29 Applications Development

How To Write A Clinical Trial In Sas

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

Better Safe than Sorry: A SAS Macro to Selectively Back Up Files

PATROL From a Database Administrator s Perspective

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

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

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

What's New in SAS Data Management

Using SAS Enterprise Business Intelligence to Automate a Manual Process: A Case Study Erik S. Larsen, Independent Consultant, Charleston, SC

Dynamic Decision-Making Web Services Using SAS Stored Processes and SAS Business Rules Manager

Paper PO03. A Case of Online Data Processing and Statistical Analysis via SAS/IntrNet. Sijian Zhang University of Alabama at Birmingham

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

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

Developing an On-Demand Web Report Platform Using Stored Processes and SAS Web Application Server

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

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

Session Attribution in SAS Web Analytics

Optimizing System Performance by Monitoring UNIX Server with SAS

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

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

SAS 9.3 Foundation for Microsoft Windows

Configuring Situation Events in Action Manager for WebSphere Business Monitor Version 6.0

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

TU04. Best practices for implementing a BI strategy with SAS Mike Vanderlinden, COMSYS IT Partners, Portage, MI

Dell SupportAssist Version 2.0 for Dell OpenManage Essentials Quick Start Guide

Configuring Apache HTTP Server as a Reverse Proxy Server for SAS 9.3 Web Applications Deployed on Oracle WebLogic Server

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

SAS Business Data Network 3.1

SAS 9.4 Intelligence Platform

Cross platform Migration of SAS BI Environment: Tips and Tricks

A Macro to Create Data Definition Documents

WebSphere Business Monitor V7.0 Script adapter lab

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

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

9.1 SAS/ACCESS. Interface to SAP BW. User s Guide

Lost in Space? Methodology for a Guided Drill-Through Analysis Out of the Wormhole

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

Monitoring Oracle Enterprise Performance Management System Release Deployments from Oracle Enterprise Manager 12c

How to Order and Install Odette Certificates. Odette CA Help File and User Manual

Instant Interactive SAS Log Window Analyzer

WebSpy Vantage Ultimate 2.2 Web Module Administrators Guide

Managing Tables in Microsoft SQL Server using SAS

Creating Dynamic Web Based Reporting

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

Integration Guide. SafeNet Authentication Service. Integrating Active Directory Lightweight Services

ABSTRACT INTRODUCTION %CODE MACRO DEFINITION

Oracle Data Integrator 11g: Integration and Administration

Sage 200 Web Time & Expenses Guide

z/os Performance Monitoring Tools Shoot-Out: ASG, BMC, CA, Rocket

Counting the Ways to Count in SAS. Imelda C. Go, South Carolina Department of Education, Columbia, SC

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

Reporting MDM Data Attribute Inconsistencies for the Enterprise Using DataFlux

Implementing a SAS Metadata Server Configuration for Use with SAS Enterprise Guide

Documentum Content Distribution Services TM Administration Guide

Microsoft SQL Server Express 2005 Install Guide

SAS IT Resource Management 3.2

Post Processing Macro in Clinical Data Reporting Niraj J. Pandya

Managing very large EXCEL files using the XLS engine John H. Adams, Boehringer Ingelheim Pharmaceutical, Inc., Ridgefield, CT

Paper TT09 Using SAS to Send Bulk s With Attachments

System Security Fundamentals

How to Order and Install Odette Certificates. Odette CA Help File and User Manual

Optimizing Business Continuity Management with NetIQ PlateSpin Protect and AppManager. Best Practices and Reference Architecture

GFI Product Manual. ReportPack Manual

Grid Computing in SAS 9.4 Third Edition

Monitoring MSDynamix CRM 2011

NRG Software Postal Tool Kit v1.5

Encoding the Password

System Center Configuration Manager 2007

Site Store Pro. INSTALLATION GUIDE WPCartPro Wordpress Plugin Version

Internet/Intranet, the Web & SAS. II006 Building a Web Based EIS for Data Analysis Ed Confer, KGC Programming Solutions, Potomac Falls, VA

Novell Identity Manager

Scheduling in SAS 9.4 Second Edition

AN ANIMATED GUIDE: SENDING SAS FILE TO EXCEL

Scheduling in SAS 9.3

Remove Orphan Claims and Third party Claims for Insurance Data Qiling Shi, NCI Information Systems, Inc., Nashville, Tennessee

How to Setup SQL Server Replication

McAfee Directory Services Connector extension

SAS Office Analytics: An Application In Practice

Transcription:

SESUG 2012 Paper CT-02 An email macro: Exploring metadata EG and user credentials in Linux to automate email notifications Jason Baucom, Ateb Inc., Raleigh, NC ABSTRACT Enterprise Guide (EG) provides useful metadata variables to identify user credentials. Metadata can be exploited to send program notifications, but a more generic macro is required for usage in batch mode where user credentials may not be required. A flexible macro is presented that can extract email addresses by exploring metadata in an EG session or by identifying email addresses by using user credentials on a Linux system. INTRODUCTION One useful utility SAS offers is the ability to send email from programs. This can be used to notify programmers of program status, send event based notifications or deliver program results and metrics to interested parties. The typical approach is demonstrated below: FILENAME output EMAIL SUBJECT="Errors detected" FROM="admin@ateb.com" TO="jason.baucom@ateb.com"; DATA _NULL_; FILE PUT "We found errors "; RUN; The standard email utility is useful, but may require time consuming modification when code is frequently shared among team members. Our team found it bothersome to keep changing code each time an Enterprise Guide project or code segment was shared, so we sought a general and flexible solution. We operate in a heterogeneous environment, running code in both batch mode from a Linux environment and Enterprise Guide projects. In Enterprise Guide metadata can be queried to identify email addresses. User credentials may not be established in Linux, so this scenario must be accounted for as well. The mail macro needs to first identify the operating environment, discover the associated email addresses associated with the user and then send then mail. The basic flow diagram of the email macro is below (Figure 1). EG Explore Metadata to get email addresses Put email addresses in macro variable Linux or EG? Send email! Linux Query userid to get email addresses Put email addresses in macro variable DETERMINING YOUR ENVIRONMENT Figure 1. Flow diagram for email macro The first critical step is to determine in which environment the macro is executed. When a user signs into Enterprise Guide user credentials are established and can be used to determine the associated email addresses. When executing SAS code in batch mode the user may not have to establish user credentials, so we can t always rely on metadata to find our email addresses. 1

In the SAS environment the &SYSENV variable can be queried to determine if you are in batch mode or Enterprise Guide. We determined that &SYSENV is set to FORE when executing code in batch mode in Linux and BACK when running code through Enterprise Guide. The macro code is forked using an if statement %if &SYSENV = FORE %then %do; %put In batch mode; /* Get email address in Linux*/ % %else %do; %put In EG mode; /* Get email addresses in EG */ % ESTABLISHING IDENTITY IN ENTERPRISE GUIDE When user credentials are established in Enterprise Guide some environmental variables are set. The &_metauser environment variable identifies the user and can be used to query the metadata server and determine the associated email addresses. To take advantage of this aspect of this macro your system administrator needs to setup user email accounts, which can be done through Management Console (Figure 2). One very useful tool for manually exploring metadata trees is the Metadata Browser. This tool can navigate through metadata and identify where in metadata email addresses are stored. By proceeding from Person Your User EmailAddresses you can find your user email addresses, assuming that the admin has properly set them up (Figure 3). In order to connect to and begin querying the metadata server we must first set some options: options metaport=8561 metaserver="talon2.ateb.com" metauser="sasadm@saspw" metapass="yourpasswd" metarepository="foundation"; Figure 2. Exploring Metadata using Metadata Once these options are set you can begin using metadata functions to navigate the metadata tree and obtain your target metadata element. In this case our target metadata element is the Address variable. Once obtained it will be stored in a data object and subsequently in a macro variable for later consumption. First, we set up the data step and obtain the metadata object corresponding to the user. length uri address groupuri $100; call missing(uri, address, groupuri); nobj=metadata_getnobj("omsobj:person?@name = '&_metauser'",1,uri); metadata_getnobj will retrieve the Person object that has Name = &_metauser. The second parameter tells the function to retrieve only the first matching object identified. The object obtained can be referred to using the uri variable. Nobj will hold the return value of this function, the number of records we retrieve. Nobj will be set to 0 if no matching Metadata records are found or to 1 if there is a single record. If a record is found the uri reference can be used to find associated objects using the metadata_getnasn function. if nobj=0 then put 'Person not identifiable.'; else do; a=1; 2

Figure 3. Exploring Metadata using Metadata We are specifically interested in the EmailAddresses objects. A user might have multiple email addresses so the macro will need to loop over all possible email objects. The third parameter is utilized to identify which object to retrieve. We can loop over all email addresses using a variable as a counter. We initially look at the first EmailAddresses object associated with uri. If there is no email address the return code of metadata_getasn will have the value of -3 or -4. Otherwise there is confidence that at least one email address exists. A default email address is used if no email address is found. if grpassn in (-3,-4) then do; /* no email address */ address="jasonbaucom@hotmail.com"; else do while (grpassn > 0); /* loop over all available email addresses */ rc=metadata_getattr(groupuri,"address",address); put address=; a+1; The EmailAddresses object is stored in the groupuri object, so the address associated with that object can be extracted by using another metadata function. rc=metadata_getattr(groupuri,"address",address); The metadata_getattr function will place the value of the groupuri s Address attribute in the address variable. The address is stored in a dataset and the while loop continues in an attempt to identify any more email addresses. Once all email addresses associated with the user have been discovered our loop terminates with grpassn <=0 and the addresses are stored in a macro variable for later consumption. proc sql noprint; select '"' address '"' into :emailvariable separated by " " from emails; 3

ESTABLISHING IDENTITY IN LINUX User credentials are not necessarily established in batch mode, so another method is required to determine email addresses. The Linux userid can be uniquely identified using the whoami command. The result of a system command is stored in a macro variable for later use. filename getuid pipe 'whoami'; data linuxusers; infile getuid lrecl=20 pad; input uid $20.; select uid into :myid from linuxusers; %put got &myid; Since Linux accounts are not necessarily associated with a SAS account it is essential to establish a link between Linux userids and email addresses. This was hard coded in a data step. length linuxuid $8. address $100.; linuxuid = "root"; address = "jason.baucom@ateb.com"; linuxuid = "dbuller"; address = "donovan.bullerwell@ateb.com"; linuxuid = "jbaucom"; address = "jason.baucom@ateb.com"; linuxuid = "jbaucom"; address = "jasonbaucom@hotmail.com"; select '"' emailaddress '"' into :emailvariable separated by " " from emails where linuxuid = "&myid"; The end result is similar to our approach in EG, namely a macro variable that contains a list of email addresses. One potential drawback to this approach is that the macro will need to be actively maintained to reflect new users and email changes. TYING IT ALL TOGETHER AND SENDING THE EMAIL. So far it has been determined which environment we are working in and the email addresses used in the active environment have been identified. The result of this effort is a list of email addresses stored in the emailvariable macro variable. Notifications may need to be sent to other email addresses, but this cannot be determined from metadata or Linux accounts, so this information must be passed into our macro by the user. The content of our message must also be passed to the macro as well. We wrap the contents of the macro with the following definition, passing a list of email addresses, subject and email content as parameters: %macro mailteam(emaillist=, Subject=, Message=, Message2=, Message3=); The EmailList parameter can contain a list of additional email addresses or be left blank. If there is no email associated with your account available in metadata you can manually enter your email address here. The Subject variable and up to three message lines can be used as well. Missing subject or message variables will simply be left blank in the outgoing email. At the end of the macro we finally send our email: filename mymail email to=(&emaillist %nrbquote(&emailvariable) ) subject=&subject; data _null_; file mymail; put &Message; put &Message2; put &Message3; 4

The to list is a combination of the emails identified from metadata or Linux and the list of email addresses we manually entered in the macro call. The macro can be called in the following manner: %mailteam(subject="testing testing",message="did it work?"); %mailteam(emaillist= myotheremail@ateb.com, Subject="testing again",message="did it work?",message2= we need another line ); Using the EmailList variable can add additional non-identifiable email addresses to the message but it will not remove the default email addresses associated with the user account. This might be helpful if your admin has not assigned an email address to your account in Management Console or in the macro code. CONCLUSION In conclusion a useful macro is presented that facilitates the sending of email messages in a shared code environment with minimal effort. It has the ability to send emails to addresses uncovered by querying metadata in Enterprise Guide, using system commands in Linux or by sending hard coded email addresses in the macro call. See appendix for a full code. REFERENCES SAS Institute. DATA Step Functions for Reading and Writing Metadata. Retrieved 08/01/2012. Available at http://support.sas.com/documentation/cdl/en/lrmeta/60739/html/default/viewer.htm#a003091925.htm. CONTACT INFORMATION Your comments and questions are valued and encouraged. Contact the author at: Name: Jason Baucom, PhD Enterprise: Ateb Inc. Address: 2600 Sumner Blvd City, State ZIP: Raleigh, NC Work Phone: 919-882-4990 E-mail: Jason.baucom@ateb.com 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. 5

APPENDIX 1. CODE LISTING %macro mailteam(emaillist=, Subject=, Message=, Message2=, Message3=); %let ouremail=; %if &SYSENV = FORE %then %do; /* We are in batch/linux mode */ filename getuid pipe 'whoami'; data linuxusers; infile getuid lrecl=20 pad; input uid $20.; select uid into :myid from linuxusers; %put got &myid; length linuxuid $8. address $100.; linuxuid = "root"; address = "jason.baucom@ateb.com"; linuxuid = "dbuller"; address = "donovan.bullerwell@ateb.com"; linuxuid = "jbaucom"; address = "jason.baucom@ateb.com"; linuxuid = "jbaucom"; address = "jasonbaucom@hotmail.com"; select '"' address '"' into :emailvariable separated by " " from emails where linuxuid = "&myid"; % %else %do; /* We are in EG Mode */ options metaserver="server.ateb.com" metaport=8561 metauser="sasadm@saspw" metapass="sasadmpasswd" metarepository="foundation"; length uri address groupuri $100; call missing(uri, address, groupuri); nobj=metadata_getnobj("omsobj:person?@name = '&_metauser'",1,uri); if nobj=0 then put 'Person not identifiable.'; else do; a=1; if grpassn in (-3,-4) then do; /* no email address */ address="jasonbaucom@hotmail.com"; /* default */ else do while (grpassn > 0); /* loop over email addresses */ rc=metadata_getattr(groupuri,"address",address); put address=; a+1; keep address; proc sql noprint; select '"' address '"' into :emailvariable separated by " " from emails; % 6

filename mymail email to=(&emaillist %nrbquote(&emailvariable) ) subject=&subject; data _null_; file mymail; put &Message; put &Message2; put &Message3; %mend mailteam; 7