Using SAS to Control and Automate a Multi SAS Program Process. Patrick Halpin November 2008



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

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

PharmaSUG Paper AD11

AN ANIMATED GUIDE: SENDING SAS FILE TO EXCEL

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

A Method for Cleaning Clinical Trial Analysis Data Sets

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

EXTRACTING DATA FROM PDF FILES

Writing Data with Excel Libname Engine

How To Create An Audit Trail In Sas

SUGI 29 Applications Development

Creating Dynamic Reports Using Data Exchange to Excel

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

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

Automated Software Testing With Macro Scheduler

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

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

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

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

CHAPTER 1 Overview of SAS/ACCESS Interface to Relational Databases

Using SAS/FSP Software for Ad hoc Reporting By Marc Schlessel SPS Software Services Inc.

Enhancing the SAS Enhanced Editor with Toolbar Customizations Lynn Mullins, PPD, Cincinnati, Ohio

Managing Tables in Microsoft SQL Server using SAS

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

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

Search and Replace in SAS Data Sets thru GUI

A Microsoft Access Based System, Using SAS as a Background Number Cruncher David Kiasi, Applications Alternatives, Upper Marlboro, MD

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

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

You have got SASMAIL!

ASG-Rochade Backing up Rochade Databases Quick Start Guide

UNIX Operating Environment

Effective Use of SQL in SAS Programming

How To Write A Clinical Trial In Sas

Combining SAS LIBNAME and VBA Macro to Import Excel file in an Intriguing, Efficient way Ajay Gupta, PPD Inc, Morrisville, NC

An Introduction to SAS/SHARE, By Example

How to Use SDTM Definition and ADaM Specifications Documents. to Facilitate SAS Programming

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

Microsoft Windows PowerShell v2 For Administrators

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

SAS Credit Scoring for Banking 4.3

ChE-1800 H-2: Flowchart Diagrams (last updated January 13, 2013)

SAS Comments How Straightforward Are They? Jacksen Lou, Merck & Co.,, Blue Bell, PA 19422

Using Proc SQL and ODBC to Manage Data outside of SAS Jeff Magouirk, National Jewish Medical and Research Center, Denver, Colorado

SAS Macros as File Management Utility Programs

Data Exchange Preparation Procedures_006. Document Control Number

Chapter 9: Building Bigger Programs

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

SUGI 29 Posters. Mazen Abdellatif, M.S., Hines VA CSPCC, Hines IL, 60141, USA

Optimizing System Performance by Monitoring UNIX Server with SAS

Extending Remote Desktop for Large Installations. Distributed Package Installs

SAS Grid Manager Testing and Benchmarking Best Practices for SAS Intelligence Platform

SAS System and SAS Program Validation Techniques Sy Truong, Meta-Xceed, Inc., San Jose, CA

VISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.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

Paper CI Marketing Campaign (Message sent) Contact Recorded in SAS System Tables. Response Recorded in SAS System Tables

Government Girls Polytechnic, Bilaspur

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

Extracting YouTube videos using SAS. Dr Craig Hansen

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

Computational Mathematics with Python

DiskPulse DISK CHANGE MONITOR

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

imhosted Web Hosting Knowledge Base

Developing Applications Using BASE SAS and UNIX

Excel 2007 Introduction to Macros

Integrating OID with Active Directory and WNA

Communications Access Methods for SAS/CONNECT 9.4 and SAS/SHARE 9.4 Second Edition

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

SAS Programming Tips, Tricks, and Techniques

Spelling Checker Utility in SAS using VBA Macro and SAS Functions Ajay Gupta, PPD, Morrisville, NC

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

Big Data, Fast Processing Speeds Kevin McGowan SAS Solutions on Demand, Cary NC

Managing Qualtrics Survey Distributions and Response Data with SAS

Oracle 10g PL/SQL Training

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, Introduction 1. 2 Invoking Shell Scripts 2

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

VHDL Test Bench Tutorial

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

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.

Computational Mathematics with Python

Computational Mathematics with Python

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

>

AN INTRODUCTION TO MACRO VARIABLES AND MACRO PROGRAMS Mike S. Zdeb, New York State Department of Health

This presentation explains how to monitor memory consumption of DataStage processes during run time.

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

Transcription:

Using SAS to Control and Automate a Multi SAS Program Process Patrick Halpin November 2008

What are we covering today A little background on me Some quick questions How to use Done files Use a simple example Quick Review Questions

A little background about me Using SAS since 1996 Certified base and advanced SAS programmer. Currently working at dunnhumbyusa in Cincinnati Ohio Work has covered pricing and elasticity, statistical analysis, modeling, optimization, reporting and communications and media. Experience in banking, gaming and transportation industries. B.S in mathematics at Elizabethtown College M.S. in Mathematics/Operations Research at The College of William and Mary.

Questions for the audience How many times has one sat around waiting for a program to end to kick off the next one? What if you don t know when it will finish? What if you have multiple dependent programs? Then this presentation may help

Don t worry this presentation has been through QA

To Control and Automate a Multi SAS Program Process one can use SAS Often times a project is comprised of many SAS programs that need to run in a given order. Additionally, the SAS programs are dependent on previous SAS programs completing. One way to accomplish and automate this task is to use Done files and the SLEEP command in SAS. Done files are files that are created when a SAS program finishes. SAS programs dependent on previous jobs finishing look for those Done files to be created. Once the Done files are created the next SAS job in the process will start.

To control and automate the process there are 4 main steps Understanding the program flow Step 1 - Creating the UNIX shell script Step 2 - Creating Done files Step 3 - Using the SLEEP command Step 4 - Putting it all together We will use a simple 5 program example case to help explain these steps

It is vital to understand the program flow 1 and 2 can run together 1 2 3 needs 2 to finish 3 4 needs 1 and 3 to finish 5 needs 4 to finish 4 5

Step 1: A shell script will control out program flow # UNIX Script #! /bin/ksh cd /Program_Directory sas prog_1.sas & sas prog_2.sas sas prog_3.sas sas prog_4.sas sas prog_5.sas 1. Prog_1 and Prog_2 will run at the same time 2. Prog_3 runs when Prog_2 completes 3. Prog_4 runs when Prog_3 completes 4. Prog_5 runs when Prog_4 completes 5. Point 3 is NOT what we want to do 6. Prog_4.sas must start after BOTH prog_3.sas AND prog_1.sas 7. We need Done files and the SLEEP command

Step 2: Done Files are used to tell us about the status of a SAS program For our example we will create Done files when a SAS program has finished running We will need to add code to the start and end of the SAS programs At the start one deletes an existing Done files At the end one creates the Done file when the program is complete

Step 2: We need code to delete any existing Done files /* Deletes an existing Done files */ Libname lib_done /program_directory/ ; %macro delete_done(var1); %if %sysfunc(exist(lib_done.done_file&var1)) %then %do; proc datasets lib=lib_done nolist; delete done_file&var1; run; %end; %mend delete_done; %delete_done(program_name); run;

Step 2: We need code to create Done files /* Creates a Done files */ %macro create_done(var1); Data lib_done.done_file&var1; done= YES ; output; run; %mend create_done; %create_done(program_name); run;

Step 3: Using the sleep command to pause a SAS program We will use the SLEEP command to pause a SAS program. This program will be paused until precedent program/process is complete. The syntax for the Sleep command is simple SLEEP(n<,unit>) This command is often used with DDE an open up excel files Here is an example where the SAS program will pause for 10 seconds Data _null_; X=Sleep(10,1); run;

Step 4: We need to put all the step together to make this work Create the UNIX script #! /bin/ksh cd /Program_Directory sas prog_1.sas & sas prog_2.sas sas prog_3.sas sas prog_4.sas sas prog_5.sas Add create/delete Done file code to programs 1, 3, 4 and 5 1 2 4 3 5

Step 4: More code is needed in program 4 Program 4 will look for the Done files from 1 and 3. Need to add a SLEEP command and loop to check for those Done files Make loop time long enough that 1 and 3 should have completed We will check every 2 minutes Have program time out with an error message if the Done file is not created in a reasonable amount of time If after the 2 hours Done files are not found 4 will not run Code will be added to 5 to stop it if 4 does not run Run the UNIX script

Step 4: Code added at the top of program 4 to check for both done files %global counter max; %let counter=0; %let max=120; /* minutes to check */ %macro done_check; %if ((%sysfunc(exist(lib_done.done_prog_1)))=0 or (%sysfunc(exist(lib_done.done_prog_3)))=0) %then %do; %do %until (((%sysfunc(exist(lib_done.done_prog_1)))=1 and (%sysfunc(exist(lib_done.done_prog_3)))=1) or (&counter+0 > &max+0)); data _null_; sleep_time=sleep(60,1); *** sleep for a minute ***; run; %let counter=%eval(&counter.+1); *** increment counter ***; %end; %end;

Step 4: Code to stop program 4 if done files not found in time *** Stop program if time out ***; %if &counter+0 > &max+0 %then endsas; %mend done_check; %done_check; run;

Step 4: Check at the start of program 5 to confirm 4 finished successfully /* Code added to the top of prog_5 */ /* To stop it if 4 does not run */ Libname lib_done /program_directory/ ; %macro check(var1); %if sysfunc(exist(lib_done.done_file&var1))=0 %then endsas; %end; %mend check; %check(prog_4); run;

A quick review of the process Know the program flow 4 main steps Shell script Done files Sleep command Put it all together Adding code at the start and end of programs To check to see when and how programs ended

Done files and the Sleep command can Control and Automate a Multi SAS Program Process Projects often consist of multiple SAS programs, the dependences and order of processing can become increasingly complex. What we have discussed above is a simple solution that can be used anywhere SAS exists. Using just a UNIX shell script and a couple of commands within your programs, processes can be streamlined. Many more bells and whistles can be added to the UNIX script and the Done files to build out the process further to increase robustness and efficiency.

Questions

Thank You