Chasing the log file while running the SAS program

Similar documents
Using SAS to Control and Automate a Multi SAS Program Process Patrick Halpin, dunnhumby USA, Cincinnati, OH

Virtual Accessing of a SAS Data Set Using OPEN, FETCH, and CLOSE Functions with %SYSFUNC and %DO Loops

A SAS Macro Utility to Modify and Validate RTF Outputs for Regional Analyses Jagan Mohan Achi, PPD, Austin, TX Joshua N. Winters, PPD, Rochester, NY

SAS Data Integration Studio Take Control with Conditional & Looping Transformations

Automated Checking Of Multiple Files Kathyayini Tappeta, Percept Pharma Services, Bridgewater, NJ

SAS Simulation Studio 14.1: User s Guide. Introduction to SAS Simulation Studio

Error Trapping Techniques for SCL. Andrew Rosenbaum, Trilogy Consulting, Kalamazoo, MI

Submitting Code in the Background Using SAS Studio

Application Interface for executing a batch of SAS Programs and Checking Logs Sneha Sarmukadam, inventiv Health Clinical, Pune, India

SAS2VBA2SAS: Automated solution to string truncation in PROC IMPORT Amarnath Vijayarangan, Genpact, India

3N Validation to Validate PROC COMPARE Output

epaystub 2015 Build Notes ENCORE BUSINESS SOLUTIONS twitter.com/encorebusiness.com

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

Extending the Scope of Custom Transformations

PharmaSUG Paper TT11

The Output Bundle: A Solution for a Fully Documented Program Run

Document and Enhance Your SAS Code, Data Sets, and Catalogs with SAS Functions, Macros, and SAS Metadata. Louise S. Hadden. Abt Associates Inc.

Making the most of SAS Jobs in LSAF

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

PharmaSUG Paper PO10

Using UNIX Shell Scripting to Enhance Your SAS Programming Experience

epaystub 2016 Build Notes ENCORE BUSINESS SOLUTIONS twitter.com/encorebusiness.com

Text Generational Data Sets (Text GDS)

Your Own SAS Macros Are as Powerful as You Are Ingenious

Patricia Guldin, Merck & Co., Inc., Kenilworth, NJ USA

Useful Tips When Deploying SAS Code in a Production Environment

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

When Powerful SAS Meets PowerShell TM

TLF Management Tools: SAS programs to help in managing large number of TLFs. Eduard Joseph Siquioco, PPD, Manila, Philippines

SASGSUB for Job Workflow and SAS Log Files Piyush Singh, Prasoon Sangwan TATA Consultancy Services Ltd. Indianapolis, IN

QuickStart Guide 2 - Normalisation

Interactive SAS Analysis Service (isas) within AIX Unix SAS Server. Stanley Wei Sep 9, 2016

How to use UNIX commands in SAS code to read SAS logs

A Tool to Compare Different Data Transfers Jun Wang, FMD K&L, Inc., Nanjing, China

LST in Comparison Sanket Kale, Parexel International Inc., Durham, NC Sajin Johnny, Parexel International Inc., Durham, NC

Automation of makefile For Use in Clinical Development Nalin Tikoo, BioMarin Pharmaceutical Inc., Novato, CA

My SAS Grid Scheduler

How a Code-Checking Algorithm Can Prevent Errors

CHAPTER 7 Examples of Combining Compute Services and Data Transfer Services

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

SAS Job Monitor 2.2. About SAS Job Monitor. Overview. SAS Job Monitor for SAS Data Integration Studio

CEU Online System, The Friday Center for Continuing Education, UNC-Chapel Hill How to Obtain Participant IDs for Awarding of CEUs

How to use CPCS-ON System: PREPARING A BATCH FOR NOTIFICATION

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

Tracking Dataset Dependencies in Clinical Trials Reporting

The Next Generation Smart Program Repository

Regaining Some Control Over ODS RTF Pagination When Using Proc Report Gary E. Moore, Moore Computing Services, Inc., Little Rock, Arkansas

Check Services vs. Payables Web Services sm

Rupinder Dhillon Dec 14, 2012 TASS-i

SAS Model Manager 15.1: Quick Start Tutorial

Copy That! Using SAS to Create Directories and Duplicate Files

A Tool to Reduce the Time Used in the Preparation of the Statistical Review Aid Used for Electronic Submission

PharmaSUG Paper CC02

SAS Macro Dynamics: from Simple Basics to Powerful Invocations Rick Andrews, Office of Research, Development, and Information, Baltimore, MD

Performance Monitors Setup Guide

Run your reports through that last loop to standardize the presentation attributes

Modern Requirements4TFS 2018 Update 1 Release Notes

Batch vs. Interactive: Why You Need Both Janet E. Stuelpner. ASG. Inc Cary. North Carolina

Make SAS Enterprise Guide Your Own. John Ladds Statistics Canada Paper

PharmaSUG China Paper 059

Paperless Tax Office Automation

Building Flexible Jobs in DataFlux

Write SAS Code to Generate Another SAS Program A Dynamic Way to Get Your Data into SAS

Easy Comext (or Easy XTnet) is an HTML based interface giving to the public at Eurostat s External Trade database.

Paperless Tax Office Automation

Gas Safe Notification User Guide

Speed Dating: Looping Through a Table Using Dates

Troy Martin Hughes ABSTRACT INTRODUCTION

An Alternate Way to Create the Standard SDTM Domains

Paperless Tax Office Automation

ACTIVANT. Prophet 21 ACTIVANT PROPHET 21. New Features Guide Version 11.0 ADMINISTRATION NEW FEATURES GUIDE (SS, SA, PS) Pre-Release Documentation

STA 303 / 1002 Using SAS on CQUEST

A Macro that can Search and Replace String in your SAS Programs

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

SAS Clinical Data Integration 2.4

HAVE YOU EVER WISHED THAT YOU DO NOT NEED TO TYPE OR CHANGE REPORT NUMBERS AND TITLES IN YOUR SAS PROGRAMS?

A Utility Program for Quickly Identifying LOG Error or Warning Messages

A Macro to Create Program Inventory for Analysis Data Reviewer s Guide Xianhua (Allen) Zeng, PAREXEL International, Shanghai, China

Cleaning up your SAS log: Note Messages

Applications Development

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

Functions vs. Macros: A Comparison and Summary

Let your customers login to your store after pre-approval

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

Registering / Logging In to the POTA Statistics System. Go to stats.parksontheair.com. From this screen, click Login/Logout in the Navigation Menu

Divide and Conquer Writing Parallel SAS Code to Speed Up Your SAS Program

SAS ENTERPRISE GUIDE USER INTERFACE

Macro Method to use Google Maps and SAS to Geocode a Location by Name or Address

Oh Quartile, Where Art Thou? David Franklin, TheProgrammersCabin.com, Litchfield, NH

Clinical Data Visualization using TIBCO Spotfire and SAS

Quick and Efficient Way to Check the Transferred Data Divyaja Padamati, Eliassen Group Inc., North Carolina.

Automate Secure Transfers with SAS and PSFTP

SAS Studio: A New Way to Program in SAS

Provisioning Systems and Other Ways to Share the Wealth of SAS Across a Network Jason Losh and Michael King, SAS Institute Inc.

Matt Downs and Heidi Christ-Schmidt Statistics Collaborative, Inc., Washington, D.C.

CHAPTER 7 Using Other SAS Software Products

Responding to Tracking Items

Table of Contents... ii. Go Ahead Bring Your Own Device to Work... 1 Requirements... 1

Tips and Tricks for Organizing and Administering Metadata

QuickStart Guide 2 - Normalisation

Transcription:

Paper 1762-2014 Chasing the log file while running the SAS program Harun Rasheed, Cognizant Technology Solutions; Amarnath Vijayarangan, Genpact ABSTRACT Prompt error alerts through emails while an error is encountered, will help user to save the run time and restrict the creation of empty datasets from the subsequent codes. It also helps in monitoring the status of the SAS programs submitted without being in front of the computer. While running the program, if SAS finds any error in the current line, it will skip the current statement and will start executing the next statement and the process will be complete only after the execution of the end statement of the program. There are programs which takes more than a day to complete. In such cases, user has to open the log file in read only mode very frequently to check for errors, warnings and unexpected notes. The user will have to terminate the execution of program manually if any such messages are identified else the user will be notified with the errors in the log file only at the end of the execution. Our proposal is to run the parallel utility program along with the production program to check the log file of the current SAS program and to notify the user through an email while encountering an error, warning or unexpected notes in the log file. Also the execution can be terminated automatically and the user can be notified if any potential messages are identified. INTRODUCTION Most of the SAS users are using either utility program to identify errors, warnings and unexpected notes or getting notified through an email to find the errors only after the full execution of the SAS job. As of now, most of these programs will help a user to check the log file only after the full execution of the SAS job. The idea of this paper is to check the log file while the program is in the execution mode by running the utility macro in parallel. Using this utility macro any one of the following could be done: User may receive the error messages through an email and if required, the user shall terminate the job manually. User may receive the error messages through an email and auto terminate option can be chosen in the utility program. If email option is not available, User can skip the notification through email and can auto terminate the execution. THE NEED FOR PARALLEL RUN AND THE POWER OF SYSTASK STATEMENT Checking the log file through an automated utility macro makes it easier for the programmer to ensure that the program ran as expected. In common these kind of utility macros are used only on the completed tasks. To trace the log file of a running SAS program, we need to execute another SAS utility macro in parallel. Through the utility macro, log file of the main program can be traced out during the execution. By default, SAS does not allow any user to execute two SAS programs in parallel, to do so some special statements needs to be called. In SAS, we have a special statement called the SYSTASK. The SYSTASK statement is used to execute the system specific commands through SAS. SYSTASK runs the commands as asynchronous tasks, which means that these tasks execute independently of all other tasks that are currently running. In our case, SYSTASK statement is used to run the chasethelog.sas in parallel so that the log traceability will start while the execution of main code starts. IMPORTANCE OF EMAIL COMMUNICATION Email communication plays a vital role in every industry. SAS enables us to send e-mail by way of a DATA step, SAS procedure, or SCL. The setup and the interfaces depend on the organization and their server operating system. In practice, email communication in SAS software is used to send successful completion notification, the generated reports as an attachment, and so on. In our case, email option is used to send the auto termination message if errors, warnings or unexpected notes are found in the log during the execution. This kind of alert helps the user to terminate the execution manually if the error/warning/unexpected notes would cause any problem to the final output. 1

%CHASETHELOG MACRO The following lines of code should be placed at the beginning of every long running program %macro chasethelog(emailid=, EndProcess=); data _null_; file 'chasethelog.sas'; put '%let StartTime = ' "%sysfunc(putn(%sysfunc(datetime()), datetime16.));"; put '%let User= '"%upcase(&sysuserid);"; put '%let PgmName='"%scan(%scan(&SYSPROCESSNAME,2,' '),1,'.');"; put '%let emailid=' "&emailid;"; put '%let procid='"&sysjobid;"; put '%let EndProcess=' "&EndProcess;"; put '%include "'chasethelog_main.sas";'; systask command "chasethelog.sas"; %mend chasethelog; This macro creates new macro variables for Execution Start Time, User ID, Main Program Name, Unix Job ID, Email ID and auto termination process. Along with the creation of macro variables, chasethelog_main.sas code will be called as an include file, whereas chasethelog_main.sas has an algorithm to perform the auto termination and email notification. PROGRAM EXECUTION FLOW: The program will be executed as per the flow given in the Figure 1. The %Chasethelog macro should be placed at the top of the long running program. The %chasethelog_main.sas should be modified as per requirement and placed in the same folder where the main program exists. When the initial setup is done, then the main program can be executed in the batch submission mode. As soon as the execution starts the %Chasethelog macro creates the new program called chasethelog.sas and this program will be saved in the folder where the long running program exists. The %Chasethelog macro will start the execution as soon as systask statement executes and the code present below %Chasethelog macro will be executed as usual. If any hazardous messages were found, then the action will be taken based on %Chasethelog macro call. Execution ends normal if no hazardous messages were found. Copy %Chasethelog macro at the top of the main program Modify %chasethelog_main macro as per the requirement and keep it in the folder where main program exists Execute the main program in batch mode As soon as the execution starts %Chasethelog macro will start tracing the main program log file If any error, warning or unexpected notes are found in the main program log file, then the action will be taken based on the algorithm used in %chasethelog_main macro The execution of %Chasethelog macro ends as soon as the execution of main programs ends. i.e. either by auto termination done by the macro or the main program execution ends Figure 1. Execution flow diagram 2

FUNCTIONALITY OF %CHASETHELOG MACRO As soon as the execution of main program starts, chasethelog macro creates the new program chasethelog.sas and starts executing using the systask statement. This code reads the main program s log file line by line. Initially it will read log file from the first line to the number of lines available at the time of execution and these observations are saved in a dataset. A flag variable is set on the last record to read the log file and identify the number of observation read on the last execution. The dataset will be checked for the errors, warnings and unexpected notes. If an error is found and the auto termination had been set to yes, then this code will kill the job using the current job ID. If the email ID has been set in the macro then auto termination message will be sent as a notification mail. If only warnings or unexpected messages are found then only a notification email will be sent to the user. Termination of the job happens only if error messages are found, even if the auto termination has been set to yes. If auto termination is set to No and email ID has been set in the macro, only notification email will be sent to the user and user can take the action based on his requirement. If macro dose not find any issue, it will read the next set of observation from the log file. From second time onwards the log file will be read from the last record read on the log file during the previous observation to the observation currently available. The last record can be found using the flag variable set during the previous execution. If the main program does not encounter any issue until the execution completes then chasethelog macro will stop executing without any action. But a successful notification will be sent to the user on completion. In any software, the way of coding, the usage and the method of execution is based on the operating system and environment setup, SAS is not an exception. In this paper the code written for %chasethelog_main works fine on unix environment with server setup. Little tweaking of the code may be required while working on the other environment. USAGE OF CHASETHE LOG MACRO AND ITS SAMPLE CALLS Chasethelog macro can be called in three ways based on the requirement. Each way of calling the macro has different functionality,which are as follows: 1) To receive only error notification through an email: %chasethelog(emailid=aaa@bbb.com, EndProcess=N); 2) To terminate the execution of SAS program as soon as the error message has been encountered in log file and receive thenotification through an email: %chasethelog(emailid=aaa@bbb.com, EndProcess=Y); 3) To auto terminate the SAS execution as the error message has been encountered in log file: %chasethelog(emailid=, EndProcess=Y); In both the first and second case, we receive other notification through an email. BENEFITS User is alerted of an error through an email even when one is not in front of the computer. The user can take immediate action once he receives the email with the error/warning message. SAS Program continues running even after it encounters "Unexpected Notes" and "Warnings" thus occupying server space by creating empty datasets, this utility can help identify the errors and thereby user can terminate the program automatically instead of letting the program run completely thereby increasing the server space utilization LIMITATIONS Every application or utility have some limitation and ours is not an exception. Our utility macro is applicable only while running the SAS program in BATCH mode. If either email id or auto termination of the process is not requested then this utility does not serve any purpose. ACKNOWLEDGEMENT Our special thanks to Mr. Ravi Kumar, Genpact for helping us to complete this paper. 3

CONTACT INFORMATION Your comments and questions are valued and encouraged. Authors contact details: Name: Harun Rasheed, Name: AmarnathVijayarangan, Phone: +91-9739261720 Phone: +91-9035032784 +91-8496999333 +91-9916611850 Email: harun_btech@yahoo.co.in Email: amarnath7@gmail.com raasheed.harun@gmail.com av0224@gmail.com TRADEMARK 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. 4

APPENDIX %macro chasethelog_main; %let JobStatus=1; %let Toread=1; %let EndJob=0; %let TraceWarn=0; %let TraceError=0; %let Iteration=0; %do %until(&jobstatus=0); %let SendMail=0; %let Track=0; %let WarnFlag=0; %let ErrorFlag=0; filenamerunlog pipe "cat &PgmName..log"; data a; infilerunloglrecl=32000 length=linelength end=eof %if &Iteration>0 %then firstobs=&toread;; input logline $varying700. linelength ; if index(logline,'error:') or upcase(substr(left(logline),1,8))='warning:' or index(logline,'uninitialized') > 0 or index(logline,'repeats of BY values') > 0 or index(logline,'w.d format') > 0 or index(logline,'invalid') > 0 or index(logline,'mathematical operations could not') > 0 or upcase(substr(left(logline),1,10))='user ERROR' or upcase(substr(left(logline),1,12))='user WARNING' or index(logline,'outside the axis range') > 0 or index(logline,'values have been converted') or index(logline,'missing') >0 then do; callsymputx('sendmail', '1'); if index(logline,'error:')=0 then call symputx('warnflag',1); output; end; if index(logline,'error:') then do; callsymputx('errorflag',1); if "&EndProcess"="Y" and &EndJob=0 then call symputx('endjob',1); end; callsymputx ('nrecord',_n_); %let toread=%eval(&nrecord+&toread); %let TraceWarn=%eval(&TraceWarn+&WarnFlag); %let TraceError=%eval(&TraceError+&ErrorFlag); %if &SendMail=1 and &emailid^= %then %do; filenamesendm email to="&emailid" Subject=%if &ErrorFlag=1 %then "Error Occured in the &PgmName..sas Program" Program";; data a; %else "Suspicious lines Occured in the &PgmName..sas set a; output; logline=''; 5

data _null_; output; set a; filesendm; put logline; %if &EndJob %then %do; x "kill &procid"; %if &emailid^= %then filename Stats email to="&emailid" Subject="%upcase(&PgmName.).sas Program is done with ERROR"; ; data _null_; file Stats; %let JobStatus=0; %gotoendlogcheck; filenameprc pipe "ps u"; data b; infileprc length=len; input process $varying900. len; if index(process,"&pgmname") and index(process,"&procid"); callsymputx('track',scan(process,2,' ')); %if &track^=&procid %then %do; %let JobStatus=0; %if &emailid^= %then %do; filename Status email to="&emailid" %if &TraceError>0 %then Subject="%upcase(&PgmName.).sas Program is done with ERROR"; %else %if &TraceWarn>0 %then Subject="%upcase(&PgmName.).sas Program is done with Warning"; Success";; %else Subject="%upcase(&PgmName.).sas Program is with data _null_; file Status; %EndLogCheck: %let Iteration=%eval(&Iteration+1); filename _all_ clear; %mend chasethelog_main; 6