Useful Tips When Deploying SAS Code in a Production Environment

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

Tracking Dataset Dependencies in Clinical Trials Reporting

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

Electricity Forecasting Full Circle

Your Own SAS Macros Are as Powerful as You Are Ingenious

PROGRAMMING ROLLING REGRESSIONS IN SAS MICHAEL D. BOLDIN, UNIVERSITY OF PENNSYLVANIA, PHILADELPHIA, PA

CC13 An Automatic Process to Compare Files. Simon Lin, Merck & Co., Inc., Rahway, NJ Huei-Ling Chen, Merck & Co., Inc., Rahway, NJ

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

Copy That! Using SAS to Create Directories and Duplicate Files

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

%MISSING: A SAS Macro to Report Missing Value Percentages for a Multi-Year Multi-File Information System

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

A Mass Symphony: Directing the Program Logs, Lists, and Outputs

The Demystification of a Great Deal of Files

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

Parallelizing Windows Operating System Services Job Flows

A Methodology for Truly Dynamic Prompting in SAS Stored Processes

Using a Control Dataset to Manage Production Compiled Macro Library Curtis E. Reid, Bureau of Labor Statistics, Washington, DC

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

A Practical Introduction to SAS Data Integration Studio

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

Internet, Intranets, and The Web

CHAPTER 7 Examples of Combining Compute Services and Data Transfer Services

How to Create Data-Driven Lists

Upgrade Instructions. Note

Submitting SAS Code On The Side

%MAKE_IT_COUNT: An Example Macro for Dynamic Table Programming Britney Gilbert, Juniper Tree Consulting, Porter, Oklahoma

PharmaSUG 2013 CC26 Automating the Labeling of X- Axis Sanjiv Ramalingam, Vertex Pharmaceuticals, Inc., Cambridge, MA

Give me EVERYTHING! A macro to combine the CONTENTS procedure output and formats. Lynn Mullins, PPD, Cincinnati, Ohio

SAS Data Integration Studio Take Control with Conditional & Looping Transformations

ABSTRACT INTRODUCTION WORK FLOW AND PROGRAM SETUP

When Powerful SAS Meets PowerShell TM

Customising SAS OQ to Provide Business Specific Testing of SAS Installations and Updates

WHAT ARE SASHELP VIEWS?

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

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

Missing Pages Report. David Gray, PPD, Austin, TX Zhuo Chen, PPD, Austin, TX

Techniques for Writing Robust SAS Macros. Martin Gregory. PhUSE Annual Conference, Oct 2009, Basel

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

Are Your SAS Programs Running You?

Functions vs. Macros: A Comparison and Summary

Paper A Simplified and Efficient Way to Map Variable Attributes of a Clinical Data Warehouse

Create a Format from a SAS Data Set Ruth Marisol Rivera, i3 Statprobe, Mexico City, Mexico

Different Methods for Accessing Non-SAS Data to Build and Incrementally Update That Data Warehouse

PhUSE Giuseppe Di Monaco, UCB BioSciences GmbH, Monheim, Germany

PhUSE US Connect 2018 Paper CT06 A Macro Tool to Find and/or Split Variable Text String Greater Than 200 Characters for Regulatory Submission Datasets

Validation Summary using SYSINFO

PREREQUISITES FOR EXAMPLES

One Project, Two Teams: The Unblind Leading the Blind

Best Practices for Using the SAS Scalable Performance Data Server in a SAS Grid environment

Best Practice for Creation and Maintenance of a SAS Infrastructure

Using UNIX Shell Scripting to Enhance Your SAS Programming Experience

Dictionary.coumns is your friend while appending or moving data

Faculty Guide. Creating your Blank Shell for Blackboard Learn:

%Addval: A SAS Macro Which Completes the Cartesian Product of Dataset Observations for All Values of a Selected Set of Variables

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

Purchase this book at

Data Edit-checks Integration using ODS Tagset Niraj J. Pandya, Element Technologies Inc., NJ Vinodh Paida, Impressive Systems Inc.

Text Generational Data Sets (Text GDS)

Quick Start Workstation Upgrade and Installation Guide

Are Your SAS Programs Running You? Marje Fecht, Prowerk Consulting, Cape Coral, FL Larry Stewart, SAS Institute Inc., Cary, NC

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

APPENDIX 2 Customizing SAS/ASSIST Software

Tips for Mastering Relational Databases Using SAS/ACCESS

Automatic Indicators for Dummies: A macro for generating dummy indicators from category type variables

PharmaSUG Paper AD06

BreakOnWord: A Macro for Partitioning Long Text Strings at Natural Breaks Richard Addy, Rho, Chapel Hill, NC Charity Quick, Rho, Chapel Hill, NC

What Do You Mean My CSV Doesn t Match My SAS Dataset?

SAS File Management. Improving Performance CHAPTER 37

Know What You Are Missing: How to Catalogue and Manage Missing Pieces of Historical Data

ABSTRACT INTRODUCTION MACRO. Paper RF

Clinical Data Visualization using TIBCO Spotfire and SAS

Beginning Tutorials. PROC FSEDIT NEW=newfilename LIKE=oldfilename; Fig. 4 - Specifying a WHERE Clause in FSEDIT. Data Editing

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

The SERVER Procedure. Introduction. Syntax CHAPTER 8

How to Implement the One-Time Methodology Mark Tabladillo, Ph.D., MarkTab Consulting, Atlanta, GA Associate Faculty, University of Phoenix

An Automation Procedure for Oracle Data Extraction and Insertion

MetaManager 3.3 New Features Guide METAMANAGER AN IBM GLOBAL SOLUTIONS DIRECTORY OFFERING BSP Software LLC 1/5

The Power of PROC SQL Techniques and SAS Dictionary Tables in Handling Data

TIBCO Spotfire Clinical Graphics Connector for SAS Installation and Administration Guide. Software Release 2.2 August 2012

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

Using Recursion for More Convenient Macros

SCSUG-2017 SAS Grid Job Search Performance Piyush Singh, Ghiyasuddin Mohammed Faraz Khan, Prasoon Sangwan TATA Consultancy Services Ltd.

Plot Your Custom Regions on SAS Visual Analytics Geo Maps

OLAP Drill-through Table Considerations

Introduction. Understanding SAS/ACCESS Descriptor Files. CHAPTER 3 Defining SAS/ACCESS Descriptor Files

Extending the Scope of Custom Transformations

Cheat sheet: Data Processing Optimization - for Pharma Analysts & Statisticians

Cleaning Duplicate Observations on a Chessboard of Missing Values Mayrita Vitvitska, ClinOps, LLC, San Francisco, CA

So Much Data, So Little Time: Splitting Datasets For More Efficient Run Times and Meeting FDA Submission Guidelines

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

Implementing external file processing with no record delimiter via a metadata-driven approach

Transitioning from Batch and Interactive SAS to SAS Enterprise Guide Brian Varney, Experis Business Analytics, Portage, MI

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

SAS Macro Technique for Embedding and Using Metadata in Web Pages. DataCeutics, Inc., Pottstown, PA

Reading in Data Directly from Microsoft Word Questionnaire Forms

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

The Impossible An Organized Statistical Programmer Brian Spruell and Kevin Mcgowan, SRA Inc., Durham, NC

Contingency Planning and Disaster Recovery

Interactive Programming Using Task in SAS Studio

Transcription:

Paper SAS258-2014 Useful Tips When Deploying SAS Code in a Production Environment ABSTRACT Elena Shtern, SAS Institute Inc., Arlington, VA When deploying SAS code into a production environment, a programmer should ensure that the code satisfies the following key criteria: 1. The code runs without errors. 2. The code performs operations consistent with the agreed upon business logic. 3. The code is not dependent on manual human intervention. 4. The code performs necessary checks to provide sufficient quality control of the deployment process. Base SAS programming offers a wide range of techniques to support the last two aforementioned criteria. The presentation demonstrates the use of SAS macro variables in combination with simple macro programs to perform a number of routine automated tasks that are often part of the production-ready code. Some of the examples to be demonstrated include the following topics: How to check that required key parameters for successful program run are populated in the parameters file. How to automatically copy the content of the permanent folder to the newly created backup folder. How to automatically update the log file with new run information. How to check whether dataset already exists in the library. INTRODUCTION This presentation is a collection of snippets of the code that SAS programmers can use when coding routine business processes. The scripts leverage SAS procedures, data steps, and SAS macro language. DRIVER PROGRAM There are many best practices that a code developer would benefit from in his or her work. One of the simplest ones is setting up a driver program to manage code complexity and to organize code in an easy-to-follow and structured way. Driver programs can be thought of as central hubs for setting up macro parameters, performing completeness checks, executing programs in a particular order, updating a log file with new information, and other relevant tasks. The following are parts of the driver program that contain coding techniques that may be used for production code or in support of a repetitive business process. CLEANING UP THE WORK LIBRARY If a program is not run in the batch mode, it is recommended to clean the SAS work library to avoid the risk of accidentally using older versions of datasets prior to the start of a new run. This is easily accomplished through the use of the DATASETS procedure. proc datasets lib=work kill; The KILL option removes all datasets in the library. SETTING UP PARAMETERS FOR SUBSEQUENT USE A driver program is the best place to set up macro parameters for subsequent use in the process. The snippet of the code below imports a parameter file that is based on Excel and uses PROC SQL to create macro variables. The file used for this demo has two parameters: Input File1 and Report Month. 1

/** IMPORT EXCEL-BASED PARAMETERS FILE */ proc import datafile="&path\parameters_demo.xlsx" out=parameters dbms=xlsx replace; /** SET UP PARAMETERS VALUES TO BE USED THROUGHOUT THE PROCESS **/ proc sql noprint; select value into: InputFile1 from Parameters where Parameter="Input File1"; select value into: ReportMonth from Parameters where Parameter="Report Month"; quit; CHECKING COMPLETENESS OF THE PARAMETERS FILE An important quality control check is to ensure that all parameters required for successful processing have valid nonmissing values. There are different ways to accomplish this. One approach is through the use of a macro program shown below. /** MACRO PROGRAM CHECKS WHETHER ALL KEY PARAMETERS HAVE NON-MISSING VALUES **/ %macro check_parameters; %if (%str(&inputfile1) eq %str()) %then %do; %put ERROR: Missing Input information for Input File1. The program stopped running.; %abort cancel; %if (%str(&reportmonth) eq %str()) %then %do; %put ERROR: Missing Input information for Report Month. The program stopped running.; %abort cancel; %mend; %check_parameters; The statement %ABORT CANCEL stops submitted SAS program and generates error message in the SAS log. CREATING A BACKUP FOLDER It is important to create a backup folder of key datasets before making changes to them. This makes it easy to restore the prior version if needed and eliminates dependency on IT personnel. The code below creates a subfolder with the date/time of a new run and copies key datasets to this folder. The code works only in a Windows environment. 2

/** SET UP MACRO VARIABLES TO STORE DATE AND TIME OF EACH RUN **/ %let timenow=%sysfunc(compress(%sysfunc(scan(%sysfunc(time(),time.),1,':'))%sysfunc(scan( %sysfunc(time(),time.),2,':')))); %let datenow=%sysfunc(date(), date7.); /** SET UP A MACRO VARIABLE TO DEFINE PATH TO FOLDERS **/ %let path=c:\sguf2014; /** ASSIGN SAS LIBRARIES **/ libname perm "&path\permanent Data"; libname backup "&path\backup Data\Permanent_Folder_&DATENOW._&TIMENOW"; /** COPY THE CONTENT OF THE PERMANENT FOLDER TO THE BACKUP FOLDER **/ x md "&path\backup Data\Permanent_Folder_&DATENOW._&TIMENOW.\"; proc copy in=perm out=backup; INVOKING OTHER PROGRAMS A driver program is often used for invoking other programs that support repeatable business processes. The code below shows how easily programs can be called from the driver program through the use of the %INCLUDE statement. %include "&path\importdemographics.sas"; UPDATING THE LOG FILE To keep track of execution runs, it is prudent to maintain a log with key information relevant to each run. The example below updates the log file with information about the date and time of the run, report month, and input file. /** SET UP MACRO VARIABLES TO STORE DATE AND TIME OF EACH RUN **/ %let timenow=%sysfunc(compress(%sysfunc(scan(%sysfunc(time(),time.),1,':'))%sysfunc(scan (%sysfunc(time(),time.),2,':')))); %let datenow=%sysfunc(date(), date7.); /** ADD EXECUTION RUN INFO TO THE EXECUTION LOG DATASET **/ data new_run_info; format Date $9. Time $4. inputdata $30. reportmonth $7.; Date="&datenow"; Time="&timenow"; inputdata="&inputfile1"; reportmonth="&reportmonth"; 3

proc append data=new_run_info base=perm.execution_log; proc delete data=new_run_info; The added record looks as follows in the dataset EXECUTION_LOG: Display 1: Screenshot of the added record CHECK TO SEE IF A SAS DATASET EXISTS If a process is dependent on the presence of a particular dataset, it is prudent to have code that checks whether such a dataset exists and generates an error message when the dataset is not found. The code below checks whether dataset CITIYR exists in the SAS library SASHELP. /** CHECK IF A DATASET CITIYR EXISTS IN THE SASHELP LIBRARY **/ %macro check_db; %if %sysfunc(exist(sashelp.citiyr)) %then %goto exit; %else %do; %put ERROR: Dataset CITIYR is not found. The program stopped running. ; %abort cancel; %exit: %mend check_db; %check_db; The statement %ABORT CANCEL stops submitted SAS program and generates error message in the SAS log. HOW TO AVOID APPENDING DUPLICATE RECORDS TO A MASTER DATASET Business processes often involve updating a master dataset with new or updated records. To avoid appending duplicate records, especially when no time stamp information is present to differentiate between the older and newer records, one can leverage the code below to remove records in the master dataset that are being updated with new information. The code below uses the dataset CITIYR in the SAS library SASHELP. The dataset CITIYR has 10 records with yearly data from 1980 through 1989. For demo purposes, the dataset CITIYR_UPD is created with two records, one for year 1989 and one for year 1990. /** CREATE A MOCK UP INTERIM DATASET TO BE ADDED TO A MASTER DATASET **/ data Citiyr_Upd; set sashelp.citiyr; if _n_<=2; if year(date)=1980 then date='01jan1989'd; else date='01jan1990'd; proc sql noprint; select distinct year(date) into: Year separated by ',' from Citiyr_Upd; quit; The macro program below updates the master dataset CITIYR with updated information for 1989, since the record for 4

1989 already exists in dataset CITIYR, and adds a new record for the year 1990. Once the macro program is complete, dataset CITIYR has 11 records. /** FIRST, CHECK IF A MASTER DATASET EXISTS. IF YES, CHECK WHETHER RECORDS FOR **/ /** THE SAME PRIMARY KEY ALREADY EXIST IN THE MASTER DATASET. IF YES, REPLACE **/ /** THE OLDER RECORDS WITH NEWER RECORDS. **/ /** IF THIS IS THE FIRST TIME THE RECORDS ARE ADDED TO THE MASTER DATASET, **/ /** NO CHECKS ARE REQUIRED, AND ALL RECORDS CAN BE APPENDED. **/ %macro append_record; %macro a; %mend a; %if %sysfunc(exist(sashelp.citiyr)) %then %do; proc sql; create table Citiyr_Temp as select * from sashelp.citiyr where year(date) notin (&Year); proc append data=citiyr_upd base=citiyr_temp; data Citiyr; set Citiyr_Temp; proc delete data=citiyr_temp; %else %do; data Citiyr; set sashelp.citiyr; proc append data=citiyr_upd base=citiyr; %mend append_record; %append_record; CONCLUSION Base SAS programming offers a wide range of programming techniques to perform quality control checks of the deployment process and to minimize dependency on the manual input. This presentation focused on sharing simple techniques which programmers can apply in various situations. REFERENCES SAS 9.4 Product Documentation at http://support.sas.com/documentation/94/index.html SAS Technical Papers at http://support.sas.com/rnd/ 5

CONTACT INFORMATION Your comments and questions are valued and encouraged. Contact the author: Elena Shtern 1530 Wilson Blvd, Suite 800 Arlington, VA 22209 SAS Institute Inc. Elena.Shtern@sas.com http://www.sas.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