Sending Text Messages from SAS

Similar documents
Copy That! Using SAS to Create Directories and Duplicate Files

ABSTRACT MORE THAN SYNTAX ORGANIZE YOUR WORK THE SAS ENTERPRISE GUIDE PROJECT. Paper 50-30

Macro Quoting: Which Function Should We Use? Pengfei Guo, MSD R&D (China) Co., Ltd., Shanghai, China

A Generalized Macro-Based Data Reporting System to Produce Both HTML and Text Files

DocAve Online 3. Release Notes

While You Were Sleeping, SAS Was Hard At Work Andrea Wainwright-Zimmerman, Capital One Financial, Inc., Richmond, VA

Journey to the center of the earth Deep understanding of SAS language processing mechanism Di Chen, SAS Beijing R&D, Beijing, China

Getting Started Reliance Communications, Inc.

Going Under the Hood: How Does the Macro Processor Really Work?

Using SAS Enterprise Guide to Coax Your Excel Data In To SAS

Travelers Rest Festival Privacy Policy. Privacy Policy. PRIVACY POLICY LAST UPDATED: MAY

Macro Facility. About the Macro Facility. Automatic Macro Variables CHAPTER 14

is still the most used Internet app. According to some studies around 85% of Internet users still use for communication.

Using Metadata Queries To Build Row-Level Audit Reports in SAS Visual Analytics

One SAS To Rule Them All

Better Metadata Through SAS II: %SYSFUNC, PROC DATASETS, and Dictionary Tables

Files Arriving at an Inconvenient Time? Let SAS Process Your Files with FILEEXIST While You Sleep

Miracle Service Accent

Improving Your Relationship with SAS Enterprise Guide Jennifer Bjurstrom, SAS Institute Inc.

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

The QuickStudy Guide for Zoho CRM

SAS Visual Analytics Environment Stood Up? Check! Data Automatically Loaded and Refreshed? Not Quite

Simplifying Your %DO Loop with CALL EXECUTE Arthur Li, City of Hope National Medical Center, Duarte, CA

Introduction. Getting Started with the Macro Facility CHAPTER 1

Taking advantage of the SAS System on OS/390

Step through Your DATA Step: Introducing the DATA Step Debugger in SAS Enterprise Guide

Get Started Writing SAS Macros Luisa Hartman, Jane Liao, Merck Sharp & Dohme Corp.

SAS Macro Dynamics - From Simple Basics to Powerful Invocations Rick Andrews, Office of the Actuary, CMS, Baltimore, MD

Instructions for Backpage Easy Ad Submitter from Coolmarketingsoftware.com

The SAS Interface to REXX

Implementation Guide. SmartOffice Sync for Microsoft Exchange

Using Recursion for More Convenient Macros

Using SAS/SCL to Create Flexible Programs... A Super-Sized Macro Ellen Michaliszyn, College of American Pathologists, Northfield, IL

CMS Enterprise Portal User Manual

KEYWORDS Metadata, macro language, CALL EXECUTE, %NRSTR, %TSLIT

SAS 9 Programming Enhancements Marje Fecht, Prowerk Consulting Ltd Mississauga, Ontario, Canada

Campus Community Guide October 2012

An Efficient Method to Create Titles for Multiple Clinical Reports Using Proc Format within A Do Loop Youying Yu, PharmaNet/i3, West Chester, Ohio

Getting it Done with PROC TABULATE

Creating a Departmental Standard SAS Enterprise Guide Template

Smart Bulk SMS & Voice SMS Marketing Script with 2-Way Messaging. Quick-Start Manual

QUEST Procedure Reference

AWS Elemental MediaStore. User Guide

User Guide. Copyright 2015 Cybercom Software

Parallelizing Windows Operating System Services Job Flows

USING SAS HASH OBJECTS TO CUT DOWN PROCESSING TIME Girish Narayandas, Optum, Eden Prairie, MN

Paper AD12 Using the ODS EXCEL Destination with SAS University Edition to Send Graphs to Excel

Paper HOW-06. Tricia Aanderud, And Data Inc, Raleigh, NC

Essential ODS Techniques for Creating Reports in PDF Patrick Thornton, SRI International, Menlo Park, CA

How to Incorporate Old SAS Data into a New DATA Step, or What is S-M-U?

Windows: SPX Access Method

Let the CAT Out of the Bag: String Concatenation in SAS 9

When Powerful SAS Meets PowerShell TM

Producing Summary Tables in SAS Enterprise Guide

Web Metrics at Scale: Using Base SAS to Access Google Analytics APIs

SAS Data Libraries. Definition CHAPTER 26

AMCTHEATRES.COM - PRIVACY POLICY

Welcome to United Bank - Mobile Banking!

Give m Their Way They ll Love it! Sarita Prasad Bedge, Family Care Inc., Portland, Oregon

A Maintenance-Free Menu Driven Closure System by Stephen M. Noga, Rho, Inc.

OS/2: SPX Access Method

What to Expect When You Need to Make a Data Delivery... Helpful Tips and Techniques

Multi-Factor Authentication FAQs

Using a Picture Format to Create Visit Windows

CHAPTER 7 Using Other SAS Software Products

IBM. Documentation. IBM Sterling Connect:Direct Process Language. Version 5.3

Google Apps. What are Google Apps?

A Guided Tour Through the SAS Windowing Environment Casey Cantrell, Clarion Consulting, Los Angeles, CA

One of the fundamental kinds of websites that SharePoint 2010 allows

External Files. Definition CHAPTER 38

Installation Instructions for SAS Activity-Based Management 6.2

Paper CC16. William E Benjamin Jr, Owl Computer Consultancy LLC, Phoenix, AZ

Welcome to First Security Mobile

HTML for the SAS Programmer

The Demystification of a Great Deal of Files

Create Awesomeness: Use Custom Visualizations to Extend SAS Visual Analytics to Get the Results You Need

Two-Factor Authentication over Mobile: Simplifying Security and Authentication

Is Your Data Viable? Preparing Your Data for SAS Visual Analytics 8.2

VMware Notification Service v2.0 Installation and Configuration Guide Configure ENS2 for cloud and on-premises deployments

Focus Group Analysis

Security Aspekts on Services for Serverless Architectures. Bertram Dorn EMEA Specialized Solutions Architect Security and Compliance

Guide Users along Information Pathways and Surf through the Data

SAS Viya : The Beauty of REST in Action

This Too Shall Pass: Passing Simple and Complex Parameters In and Out of Macros

Delivering Information to the People Who Need to Know Carol Rigsbee, SAS Institute Chris Hemedinger, SAS Institute

Serverless Architectures with AWS Lambda. David Brais & Udayan Das

Amazon WorkMail. User Guide Version 1.0

Unlock SAS Code Automation with the Power of Macros

To access our funding opportunities and submit a proposal, visit

A Time Saver for All: A SAS Toolbox Philip Jou, Baylor University, Waco, TX

Delivering Information to the People Who Need to Know Carol Rigsbee, SAS Institute Chris Hemedinger, SAS Institute

e180 Privacy Policy July 2018

This is being done to address the issues of privacy, security and convenience as it relates to your University of Alberta account.

Information Security Policy

IFS INTERNET SUPPORT CENTER

SAS Activity-Based Management Server Software 6.1 for Windows

VMware Notification Service v2.0 Installation and Configuration Guide Configure ENS2 for cloud and on-premises deployments

How to Create Data-Driven Lists

Creating and Executing Stored Compiled DATA Step Programs

Tenable.io User Guide. Last Revised: November 03, 2017

Transcription:

ABSTRACT Sending Text Messages from SAS Matthew Slaughter, Kaiser Permanente Center for Health Research, Portland, OR Text messages (SMS) are a convenient way to receive notifications away from your computer screen. In SAS, text messages can be sent to mobile phones via the email-sms gateway or one of a number of web APIs. This paper briefly describes various methods for sending text messages from SAS and explores possible applications. INTRODUCTION Text messages (Short Message Service or SMS) allow cell phone users to receive short messages without the need for an internet or data connection. This gives SMS an advantage compared to other forms of modern communication such as email and various social networks. Text messages are widely used for everything from private conversations to shipping notifications due to the ubiquity of cell phones and general ease of use. This paper illustrates two general methods for sending text messages programmatically, using either the cell providers' email-sms gateways or Amazon Web Services' Simple Notification Service. Where appropriate, the relative merits of various methods and syntaxes will be discussed. Afterwards I will suggest some possible applications of these techniques for SAS programmers and provide a number of examples. Finally, the relative merits of each method will be discussed as well as suggestions for other avenues to explore. EMAIL-SMS GATEWAY METHOD It is possible to send a message from an email address to a cell phone as a text message. This is done in the same manner as sending a normal email, except that instead of a conventional email address for the recipient the message should be sent to an address which consists of the phone number of the recipient and a domain which depends on their cell provider. For example, to send a message to a T-Mobile phone using the email-sms gateway, one need only send an email to an address of the form phonenumber@tmomail.net. These messages are governed by restrictions placed on them by carriers, which can vary significantly. For example, emails sent to T-Mobile phone numbers are automatically converted to MMS (Multimedia Message Service) messages if they exceed 160 characters. By contrast, AT&T maintains the @txt.att.net domain for SMS and @mms.att.net for multimedia. However, AT&T blocks messages sent using these domains by default and their customers must go online to specify which domains they will accept messages from. I recommend you investigate your carrier's policies before attempting to use this method. All major cell carriers provide an email-sms gateway, and for their customers discovering the domain it uses is easily accomplished by a quick internet search. However, some minor carriers do not have email-sms gateways, so this method may not work for all phone numbers. SAS supports three methods for sending emails from a SAS DATA step: MAPI, SMTP, and VIM. All three methods are suitable for sending text messages via an email-sms gateway, but for simplicity's sake this paper will assume the use of the SMTP (Simple Message Transfer Protocol) method. The MAPI and VIM methods work in a similar manner, but require a slightly different set of options to be set and may interact differently with the email client installed on your computer. Examples will assume the use of a webmail address such as Gmail, but this is not a requirement for the use of an email-sms gateway. 1 In order to use Gmail for this purpose you must turn on access for less secure apps. 2 Other email clients may require additional setup. Regardless, you will need to do some setup in SAS with an options statement: options emailhost= ("smtp.gmail.com" port=587 STARTTLS auth=plain id="your_address@gmail.com" pw="your_password"); 1 For a more thorough introduction to the topic and the three methods I refer readers to Erik Tilanus's paper "Using Mail Functionality in SAS" (2013). 2 Google considers many applications, including popular email clients such as Microsoft Outlook and Mozilla Thunderbird to be insecure. Since SAS may use your email client to interface with Gmail, google will require you to enable access for less secure apps. If you do not wish to do this on your main account, consider making a second one for email-sms gateway purposes. 1

The next step is to set up an ersatz fileref with the EMAIL option. 3 Rather that specifying a file location as the output destination, the EMAIL option allows you to send the content of PUT statements via the previously configured email address to whatever recipient is specified in the filename statement. You may then write your email in the same manner as you would write to a text file: filename myemail email to="address@domain.com"; data _null_; file myemail; put "Witty and insightful remarks"; In order to send a text message, the only difference is that the email address specified as the recipient in the FILENAME statement must be one constructed based on a phone number and a cell provider as explained above. AMAZON SNS METHOD Amazon SNS (Simple Notification Service) allows users to push updates to mobile devices. In addition to updates to mobile apps or emails, these updates can take the form of SMS text messages. This service is available in six AWS regions 4 and can send messages to phone numbers in over 200 countries. Amazon offers SNS users the option to pay for additional support, but otherwise use of the service is free as long as they send less than a hundred SMS messages per month. With the use of the AWS (Amazon Web Services) API, it is possible to write SAS programs which send text messages without using the email-sms gateway. Use of this method requires an AWS account and requires you to install and configure the AWS command line interface. Requests can then be issued to the API by passing commands to the operating system from SAS via X commands, the CALL SYSTEM routine, or the %SYSEXEC macro statement. Once you have created an AWS account and logged into the AWS console you can either send messages to individual phone numbers or create a topic, which allows you to send messages to each phone number subscribed to the topic simultaneously. Each topic has a code associated with it called the Topic ARN (Amazon Resource Name), which will allow you publish messages to that topic via the command line interface. 5 For example: aws sns publish --topic-arn arn:aws:sns:us-east-1:739913950676:sastest --message "Clever comments" This results in the text message "SASTEST> Clever comments " being received by any phone numbers subscribed to the topic SASTest. However, I usually find that I only need to send a message to a single number at a time, which allows me avoids the topic setup process and dispense with the cumbersome ARN code. aws sns publish - phone-number <your number here> --message "Astute witticisms" Submitting this code to AWS with the phone number in E.164 format (which means including area and country code, omitting any dashes or parentheses and putting a + at the start of the number) will send an SMS similarly to the version with the topic ARN, but without the topic name included in the message, and only to that single phone number. One option for sending such a message from a SAS program is the X statement. The X statement, or X command 6 is used to pass instructions from SAS to the operating system, and is a global statement that can be placed anywhere in a program in the same manner as an OPTIONS or a TITLE statement. Unlike those, the X statement is a declarative statement, which is to say that it takes effect at compile time unlike normal executable statements. An X command placed at the end of a program will still take effect before any DATA or PROC steps preceding it, and if placed in a DATA step the X command will ignore any conditional execution logic. By default, running an X command 3 For additional security, you can encode your password with PROC PWENCODE. 4 The available regions are us-east-1: US East (N. Virginia), us-west-2: US West (Oregon), eu-west-1: EU (Ireland), ap-northeast-1: Asia Pacific (Tokyo), ap-southeast-1: Asia Pacific (Singapore), and ap-southeast-2: Asia Pacific (Sydney). 5 Possible alternatives to using the AWS command line interface include sending API requests with PROC HTTP or calling a script from a language for which Amazon has provided an SDK. For programmatic simplicity I prefer not to use these methods. 6 Technically, X commands are issued from the SAS command line, and X statements are written as part of SAS programs, but in either case the syntax and effects are identical so the terms are often used interchangeably. 2

will cause a system window to remain open until 'exit' is entered. In order to avoid this I recommend the use of the NOXWAIT option, which closes the system window automatically. The syntax for the X statement is very simple: 7 X < command >; For example, in order to send the same text message as above, I would use the following code: options noxwait; x 'aws sns publish - phone-number <your number here> --message "Knowing utterance"'; This has the same result as if you had sent the message directly from the SNS command line interface. Alternatively, the CALL SYSTEM routine and the %SYSEXEC macro statement can both be used to pass commands from SAS to AWS. Both operate in the same manner as the X statement except for slightly more complex syntax and the fact that they can be used to pass such commands at execution time. Like all SAS call routines, CALL SYSTEM can be used as part of a DATA step and executed conditionally based on DATA step variable values and IF-THEN logic. The %SYSEXEC statement can be used as part of a macro or in open code. In Other respects, the following examples are equivalent to the X command above. options noxwait; call system('aws sns publish --phone-number <your number here> --message "Shrewd reflections"'); %sysexec aws sns publish --phone-number <your number here> --message "Intelligent observations"; APPLICATIONS The ability to send text messages from SAS is ideal for organizations which need to send notifications to large numbers of people based on existing data sets. Additionally, I believe text messages have a great deal of potential to be very useful to programmers in certain environments. For example, SAS jobs which run automatically on a schedule could contain code to notify someone when they run, or if they encounter an error. SAS programs which take exceptionally long periods of time to run might contain code to send a message when they have finished. Potentially, text messages could even contain some brief information about the results of the analysis conducted by such a program. I have included some brief examples which illustrate simple implementations of these concepts using the methods described above. RUNTIME NOTIFICATION This X statement makes use of automatic macro variables to send a notification containing the time and day whenever a program begins execution. options noxwait; x aws sns publish --phone-number <your number here> --message "Program running at &systime on &sysdate"; DATA DRIVEN SMS This DATA step reads in a dataset which contains a list people with associated birthdates and phone numbers. After checking to see if it is each person s birthday 8, The CALL SYSTEM routine is used to send a message as appropriate. data _null_; set birthdays(keep=name birthdate phone_number); if day(birthdate) EQ day(&sysdate) and month(birthdate) EQ month(&sysdate) then call system('aws sns publish --phone-number ' phone_number ' --message "Happy Birthday ' name '!"'); 7 Note that while SAS documentation suggest that commands to the operating system must be enclosed in quotes, they are in actually optional. This is useful as it allows macros to be executed inside the message without the use of macro quoting functions to allow macro execution inside the command. 8 Slightly more complex logic will be needed to deal with persons born on leap-day. 3

PREVIEWING PROCEDURE OUTPUT Many SAS procedures have options to produce output datasets, or produce output that can be captured in dataset form with an ODS OUTPUT statement. This code is a simple example reporting some of the results of the FREQ procedure via SMS. ods output onewayfreqs=freqs; proc freq data=sashelp.cars; tables type; ods output close; options emailhost = ("smtp.gmail.com" port=587 STARTTLS auth=plain id="email_address@gmail.com" pw="password"); filename myemail email to="phone_number@domain.com"; data _null_; set freqs; file myemail; stats = catx(' ','Type:',type,'Frequency:',frequency); put stats; ERROR REPORTING SAS provides a number of automatic macro variables that provide information about errors that have occurred during program execution (using the %SUPERQ macro function to prevent any dreaded open code recursion errors). The first macro defined below checks to see if an error has occurred in the last step executed, and if so sends an SMS containing the error message. The second macro checks for any errors that have occurred in the current SAS session, and reports them via text message. %macro errorcheck; %if &syserr > 6 %then %sysexec aws sns publish --phone-number <phone number> -- message "Error: %superq(syserrortext)"; %mend; %errorcheck; %macro errorsumm; %if &syscc < 4 %then %sysexec aws sns publish --phone-number <phone number> --message "Program execution has completed without errors"; %else %if &syscc = 4 %then %sysexec aws sns publish --phone-number <phone number> --message "Program execution has completed with warnings"; %else %sysexec aws sns publish --phone-number <phone number> --message "Program execution has suffered an error"; %mend; %errorsumm; CONCLUSION There is a saying that there are always at least three ways to do anything in SAS. It follows logically that this paper, in covering only two ways to send text messages from SAS, cannot possibly be comprehensive. There are a wide variety of SMS gateway services available (Twilio, Nexmo, and Clickatell are some of the more prominent options) which compete with Amazon s SNS and operate similarly. The main reason I cover SNS and not the others is because of SNS s generous allotment of free SMS messages each month, which make it ideal for a lone programmer experimenting with adding notifications to their programs. When choosing an enterprise solution for mass SMS delivery, the choice might well be a different one. That said, I am confident that the methods described provide a useful model for a wide variety of scenarios in which you may wish to send a text message from your SAS program. The email-sms gateway method allows easy 4

integration of data processing and messaging, but requires knowledge not only of the recipient s phone number but also the gateway domain of their cell provider (if there is one). Commercial gateways such as Amazon SNS have the advantage of being accessible from a wider variety of SAS programming elements and requiring only a phone number, but suffer from sometimes cumbersome API interfaces. Overall, SMS messaging offers opportunities to create both useful utilities for the SAS programmer and powerful communication tools for the enterprise. 5

REFERENCES Hemedinger, C. How to use Gmail to send a message from a SAS program. The SAS Dummy: a SAS Blog for the Rest of Us. July 31, 2013. Available at: http://blogs.sas.com/content/sasdummy/2013/07/31/gmail-from-sasprogram/ Hunley, C. (2010) SMTP E-Mail Access Method: Hints, Tips, and Tricks. Proceedings of the SAS Global Forum Conference, Seattle, WA, SAS Institute, Cary, NC, paper no. 060-2010. Hurley, G. (2006) Xamining the X Statement (and Some Other Xciting Code). Proceedings of the SAS Users Group International Conference, San Francisco, CA, SAS Institute, Cary, NC, paper no 036-31. Tilanus, E. (2013) Using Mail Functionality in SAS. Proceedings of the SAS Global Forum Conference, San Francisco, CA, SAS Institute, Cary, NC, paper no. 023-2013. Rosenbloom, M., Carpenter, A. (2013) Macro Quoting to the Rescue: Passing Special Characters. Proceedings of the SAS Global Forum Conference, San Francisco, CA, SAS Institute, Cary, NC, paper no. 005-2013. CONTACT INFORMATION Your comments and questions are valued and encouraged. Contact the author at: Name: Matthew Slaughter Enterprise: Kaiser Permanente Center for Health Research Address: 3800 N. Interstate Ave. City, State ZIP: Portland, OR 97227 E-mail: Matthew.T.Slaughter@gmail.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. 6