Pros and Cons of Interactive SAS Mode vs. Batch Mode Irina Walsh, ClinOps, LLC, San Francisco, CA

Similar documents
DESCRIPTION OF THE PROJECT

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

Customizing Your SAS Session

Data Presentation ABSTRACT

Creating Customized Patient Profiles using SAS ODS RTF and PROC TEMPLATE. Andrea Ritter, Biostatistics, Quintiles Inc.

How to Create a Custom Style

Tips and Tricks to Create In-text Tables in Clinical Trial Repor6ng Using SAS

Using ODS Object Oriented Features To Produce A Formatted Record Layout

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

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

SAS Drug Development Program Portability

Review of PC-SAS Batch Programming

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

Getting Up to Speed with PROC REPORT Kimberly LeBouton, K.J.L. Computing, Rossmoor, CA

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

Formatting Highly Detailed Reports: Eye-Friendly, Insight-Facilitating

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

Presentation Goals. Now that You Have Version 8, What Do You Do? Top 8 List: Reason #8 Generation Data Sets. Top 8 List

An Introduction to SAS/SHARE, By Example

A Table Driven ODS Macro Diane E. Brown, exponential Systems, Indianapolis, IN

Routing Output. Producing Output with SAS Software CHAPTER 6

Beginning Tutorials. bt006 USING ODS. Ban Chuan Cheah, Westat, Rockville, MD. Abstract

Generating Customized Analytical Reports from SAS Procedure Output Brinda Bhaskar and Kennan Murray, RTI International

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

SAS Display Manager Windows. For Windows

Storing and Reusing Macros

Chapter 1: Introduction to SAS

Making an RTF file Out of a Text File, With SAS Paper CC13

SAS Data Libraries. Definition CHAPTER 26

ABSTRACT INTRODUCTION

Copy That! Using SAS to Create Directories and Duplicate Files

ODS/RTF Pagination Revisit

Combining Text and Graphics with ODS LAYOUT and ODS REGION Barbara B. Okerson, HMC, Richmond, VA

Automating Comparison of Multiple Datasets Sandeep Kottam, Remx IT, King of Prussia, PA

Introduction to the SAS System

Routing the SAS Log and SAS Procedure Output

Symbol Table Generator (New and Improved) Jim Johnson, JKL Consulting, North Wales, PA

ABSTRACT INTRODUCTION THE GENERAL FORM AND SIMPLE CODE

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

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

SAS. Studio 4.1: User s Guide. SAS Documentation

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

The correct bibliographic citation for this manual is as follows: SAS Institute Inc Proc EXPLODE. Cary, NC: SAS Institute Inc.

IT S THE LINES PER PAGE THAT COUNTS Jonathan Squire, C2RA, Cambridge, MA Johnny Tai, Comsys, Portage, MI

Chapter 28 Saving and Printing Tables. Chapter Table of Contents SAVING AND PRINTING TABLES AS OUTPUT OBJECTS OUTPUT OBJECTS...

Using an ICPSR set-up file to create a SAS dataset

CHAPTER 1 Getting Started with SAS in UNIX Environments

Guidelines for Organizing SAS Code and Project Files

Lab #1: Introduction to Basic SAS Operations

Tracking Dataset Dependencies in Clinical Trials Reporting

The REPORT Procedure CHAPTER 32

Applications Development

footnote1 height=8pt j=l "(Rev. &sysdate)" j=c "{\b\ Page}{\field{\*\fldinst {\b\i PAGE}}}";

A Macro to Manage Table Templates Mark Mihalyo, Community Care Behavioral Health Organization, Pittsburgh, PA

ET01. LIBNAME libref <engine-name> <physical-file-name> <libname-options>; <SAS Code> LIBNAME libref CLEAR;

Epidemiology Principles of Biostatistics Chapter 3. Introduction to SAS. John Koval

ODS DOCUMENT, a practical example. Ruurd Bennink, OCS Consulting B.V., s-hertogenbosch, the Netherlands

What Is SAS? CHAPTER 1 Essential Concepts of Base SAS Software

Batch and Line Mode Processing in SAS Viya

PCKG: Managing SAS Macro Libraries. Magnus Mengelbier, Limelogic Ltd, London, United Kingdom

ABSTRACT KEY WORDS INTRODUCTION

2. Referencing Files and Sepng Op+ons. GIORGIO RUSSOLILLO - Cours de prépara+on à la cer+fica+on SAS «Base Programming» 47

Information Visualization

A Way to Work with Invoice Files in SAS

The EXPLODE Procedure

Print the Proc Report and Have It on My Desktop in the Morning! James T. Kardasis, J.T.K. & Associates, Skokie, IL

One SAS To Rule Them All

Paper AP14 Modifying The LogParse PassInfo Macro to Provide a Link between Product Usage in Rtrace Log and Time Used in Job Log

Using Graph-N-Go With ODS to Easily Present Your Data and Web-Enable Your Graphs Curtis A. Smith, Defense Contract Audit Agency, La Mirada, CA

Organizing Deliverables for Clinical Trials The Concept of Analyses and its Implementation in EXACT

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

Program Validation: Logging the Log

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

An Introduction to Creating Multi- Sheet Microsoft Excel Workbooks the Easy Way with SAS

SAS PROGRAMMING AND APPLICATIONS (STAT 5110/6110): FALL 2015 Module 2

Initializing and Configuring the SAS System

Why & How To Use SAS Macro Language: Easy Ways To Get More Value & Power from Your SAS Software Tools

SAS Studio 4.3: User s Guide

USER TRAINING AND SUPPORT

Data Presentation. Paper

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

100 THE NUANCES OF COMBINING MULTIPLE HOSPITAL DATA

The TRANTAB Procedure

Indenting with Style

SAS Viya 3.1 FAQ for Processing UTF-8 Data

FSEDIT Procedure Windows

Diagnosing SAS Enterprise Guide 4.1 Connectivity Problems Using the SAS Integration Technologies Configuration Utility TS-790

Six Cool Things You Can Do In Display Manager Jenine Milum, Charlotte, NC Wachovia Bank

EQuIS Data Processor (EDP) User Manual

General Methods to Use Special Characters Dennis Gianneschi, Amgen Inc., Thousand Oaks, CA

Functions vs. Macros: A Comparison and Summary

Creating Booklets Using Microsoft Word 2013 on a PC

WebLink Manual EZ-CAMP2

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

Maintaining Formats when Exporting Data from SAS into Microsoft Excel

Procedures. PROC CATALOG CATALOG=<libref.>catalog <ENTRYTYPE=etype> <KILL>; CONTENTS <OUT=SAS-data-set> <FILE=fileref;>

Perceptive Document Composition

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

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

Writing Programs in SAS Data I/O in SAS

Transcription:

Pros and Cons of Interactive SAS Mode vs. Batch Mode Irina Walsh, ClinOps, LLC, San Francisco, CA ABSTRACT It is my opinion that SAS programs can be developed in either interactive or batch mode and produce the same end results. To achieve identical results in both modes a few rules have to be followed. This paper explores the differences and limitations of developing a program in interactive SAS display manager mode versus batch mode and shows how to work around some of these limitations. The pros and cons of both approaches are discussed. Examples of techniques to achieve successful program execution in both modes are offered. INTRODUCTION The interactive SAS display manager is a powerful tool that allows you the use of explorer, log, output and results windows where you can examine your input or output SAS data, it also lets you use the enhanced editor window and view the log as you work on your code. This set of tools is very accommodating in the process of program development. The SAS Batch mode allows you to run programs in the background while you continue working in Interactive SAS, it also automatically creates a log file and output file, which you can review after the program runs. While Interactive SAS mode and Batch mode each have their advantages, there are considerable differences to pay attention to. This paper highlights the differences and limitations in the use of Interactive SAS Mode vs. Batch Mode and also provides some examples and workarounds to eliminate these differences. It is primarily directed to the novice user of SAS Software. The examples in this paper are processed by using the MS Windows XP operating system and SAS version 9.1. AUTOEXEC One factor to consider is that, in order to run programs in Batch mode, an AUTOEXEC.SAS file is required, unlike in Interactive mode. However setting up paths, libraries, options and operating environment for programs in one place is a good practice and it is recommended when using interactive mode as well. The following code provides a simple example of AUTOEXEC.SAS. /*define programs directory*/ %let ProjectPath=C:\WUSS2010; %let ProgFld=&ProjectPath.\Programs; %let Reportfld=&ProjectPath.\Reports; %let Logsfld=&ProjectPath.\Programs\Logs_Outputs; /*define macro programs directory*/ filename stdmacro "&ProjectPath.\Macros"; options sasautos = (stdmacro) mautosource; /*define libraries*/ libname rawdata "&ProjectPath\Rawdata"; To run programs in Batch mode, the AUTOEXEC.SAS file should be placed in the same folder where the programs are located. The current directory is the first place where SAS will try to locate the AUTOEXEC file. If you use the same directory structure for all of your projects you can create a dynamic AUTOEXEC file and use it for all of your projects with needed modifications. For example the directory used for this project is: 1

Figure 1 Project Directory Example Thus a standard approach can be used to create the AUTOEXEC file. The example shown accommodates both the Interactive mode as well as the Batch mode. The environmental variable SAS_EXECFILEPATH takes the values of the file path and filename from the Enhanced Editor during the Interactive mode whereas the SYSIN option specifies a Batch mode file source and its path. /*Works in batch mode*/ %let seefld=%sysfunc(getoption(sysin)); /*Works in Interactive Mode*/ %MACRO prgmpath(); %global fldnamep; %let fldnamep= ; %if %length(&seefld)=0 %then %let fldnamep=%sysget(sas_execfilepath); %MEND prgmpath; %prgmpath; %let ProjectPath=%sysfunc(ifc(&seefld=, %sysfunc(tranwrd(&fldnamep.,\programs\%scan(&fldnamep.,-1,\/),)), %sysfunc(tranwrd(&seefld.,\programs\%scan(&seefld.,-1,\/),)))); %let ProgFld=&ProjectPath.\Programs; %let Reportfld=&ProjectPath.\Reports; %let Logsfld=&ProjectPath.\Programs\Logs_Outputs; /*define macro programs directory*/ filename stdmacro "&ProjectPath.\Macros"; options sasautos = (stdmacro)mautosource; /*define libraries*/ libname rawdata "&ProjectPath\Rawdata"; Please note- If you run an AUTOEXEC program in Batch mode while Interactive SAS is open or interactively in consecutive SAS sessions, your profile will not be available and you will get the following message in your log: NOTE: Unable to open SASUSER.REGSTRY. WORK.REGSTRY will be opened instead. NOTE: All registry changes will be lost at the end of the session. WARNING: Unable to copy SASUSER registry to WORK registry. Because of this, you will not see registry customizations during this session. NOTE: Unable to open SASUSER.PROFILE. WORK.PROFILE will be opened instead. NOTE: All profile changes will be lost at the end of the session. This message is displayed if more than one SAS session is open, -RSASUSER option in the configuration file set to NORSASUSER, or regstry.sas7bitm file is corrupted. To check your option settings, run the following code: PROC OPTIONS option=rsasuser; run; 2

The RSASUSER option makes the SASUSER library read-only and makes it available in many SAS sessions. It also allows access to automatic LIBNAME definitions stored in the regstry.sas7bitm file. More information on setting the RSASUSER option is available on the SAS support web site. This message can be ignored if printing preferences and options saved in SASUSER catalog are defined in the AUTOEXEC.SAS file. /*define options*/ options nodate nonumber linesize=154 pagesize=56; options sysprint="hp Photosmart C4380 series"; options formchar=" ---- + ---+= -/\<>*"; AUTOEXEC.SAS is a default name for the file that executes right after SAS is initialized and before any user input is accepted. However, if you need to use a file, for example named SETUP.SAS, instead of the AUTOEXEC.SAS file, you can create a new action associated with running SAS programs. To create new actions choose Folder Option from the Tools menu in Windows Explorer. Figure 2 Folder Option Window Select file type SAS from the File Type tab and press Advance button to open the Edit File Type window. Figure 3 Edit File Type Window 3

Press New button and open the New Action window. Figure 4 New Action Window Enter a new action name for example Batch submit with Setup under the Action textbox and enter the following code under Application used to perform action: C:\PROGRA~1\SAS\SAS9~1.1\SAS.EXE "%1" -nologo -config C:\PROGRA~1\SAS\SAS9~1.1\SASV9.CFG -autoexec Setup.sas Now when you right click on any of the SAS programs you can choose to run you programs in batch with SETUP.SAS instead of AUTOEXEC file. Figure 5 Context Menu for SAS Program These changes can be made directly in your configuration file as well. However it is easier and more straightforward to call it AUTOEXEC.SAS. When you run a program in Batch mode the information from AUTOEXEC file will be included in the log automatically. In Interactive SAS mode you will have to run AUTOEXEC.SAS before you run a program or you can use a %include statement with OPTIONS SOURCE2 at the top of your program in order to include source code from the AUTOEXEC file in the program log. 4

LOG AND OUTPUT The main difference to consider is the speed of execution, especially when a program creates a large log file or a large output file. When you run such a program in Interactive mode the log display window and output display windows use bold fonts and colors to make it easy to read and it will take more processing time for writing these outputs whereas the log file and the output file produced in Batch mode do not use colors or bold fonts and take less processing time. One way to produce a log file and an output file when running programs in Interactive SAS display manager is to use PROC PRINTTO. In this case the log will not be printed in the log window, which will save processing time since it is redirected to a log file specified in filename statement. /*define output files*/ filename output "&Logsfld.\Program1.lst" ; filename logfile "&Logsfld.\Program1.log" ; PROC PRINTTO print=output new; PROC PRINTTO log=logfile new; -------Code Here----- PROC PRINTTO; Another way is to use dm (display manager) commands to save log and output files after processing. In this case the log and the output will be printed in the corresponding windows and processing time will not be decreased. The dm commands work in Interactive mode and will be ignored in Batch mode %sysfunc(ifc(%length(&seefld)=0, filename outputl "&Logsfld.\Program1.lst"; filename logfile "&Logsfld.\Program1.log"; dm 'log; file LOGFILE replace' log; dm 'output; file OUTPUTL replace' output;, )); One of the advantages of Batch mode is that the log and output files are generated automatically. These files are an important part of the program documentation. When we run a programs in Interactive mode we can programmatically redirect and output these files for documentation purposes. ODS RTF- THINGS TO KNOW The challenge for a programmer is to try to create a program so it can run in either mode and produce exactly the same output results. Some steps will require applying special programming code in order to produce the same output from Interactive mode and Batch mode. For example, if you use a DATA _NULL_ statement with ODS RTF you might encounter that blank lines are removed from output if you run the program in the Batch mode. For example, if we run the following code in Interactive mode: DATA class; set sashelp.class; PROC FORMAT; value $gender 'F'='Female' 'M'='Male'; PROC TEMPLATE; define style styles.land7; parent = styles.rtf; replace fonts / 'TitleFont2' = ("Courier New, Courier",7pt) 5

'TitleFont' = ("Courier New, Courier",7pt) 'StrongFont' = ("Courier New, Courier",7pt) 'EmphasisFont' = ("Courier New, Courier",7pt) 'FixedEmphasisFont' = ("Courier New, Courier",7pt) 'FixedStrongFont' = ("Courier New, Courier",7pt) 'FixedHeadingFont' = ("Courier New, Courier",7pt) 'BatchFixedFont' = ("Courier New, Courier",7pt) 'FixedFont' = ("Courier New, Courier",7pt) 'headingemphasisfont' =("Courier New, Courier",7pt) 'headingfont' = ("Courier New, Courier",7pt) 'docfont' = ("Courier New, Courier",7pt); replace body from document/ leftmargin = 1 in rightmargin = 1 in topmargin = 1 in bottommargin = 1 in; end; ods output OneWayFreqs=OneWayFreqs; PROC FREQ data=class; tables sex; format sex $gender.; ods output close; %let title1=class 2010; %let linesize=154; %let pagesize=56; options nodate nonumber orientation=landscape ps=&pagesize ls=&linesize; ods rtf file="&reportfld.\imode_output.rtf" style=styles.land7; ods noresults; ods listing close; DATA _null_; set OneWayFreqs end=lastobs; retain pageno 0; file print linesleft=remain notitles n=1; if _n_=1 then link header; put /@4 F_Sex @20 Frequency @40 Percent; if (lastobs) then link footer; header: put _page_; pageno+1; put @1 "&title1." ; put @1 62 *'_' /@4 'Gender' @20 ' Number in Class' @40 'Percent of total (%)' /@1 62 *'_'; footer: put @1 62 *'_' /@1 "&ProjectPath.\Programs\Program1.sas"; ods listing; ods rtf close; The output produced by the code above: 6

Figure 6 ODS RTF Output run in Interactive SAS mode However, when we submit the same code in Batch mode, the blank lines will be eliminated from the output. Figure 7 ODS RTF run in Batch mode The ODS ESCAPECHAR-'^' with PUT ^\~ at the place of blank line provides a solution to keep all blank spaces while running program in Batch mode. ods escapechar='^'; options nodate nonumber orientation=landscape ps=&pagesize ls=&linesize; ods rtf file="&reportfld.\imode_output.rtf" style=styles.land7; ods noresults; ods listing close; DATA _null_; set OneWayFreqs end=lastobs; retain pageno 0; file print linesleft=remain notitles n=1; if _n_=1 then link header; put '^\~'; put @4 F_Sex @20 Frequency @40 Percent; if (lastobs) then link footer; header: put _page_; pageno+1; put @1 "&title1." ; put @1 62 *'_' ; put '^\~' ; put @4 'Gender' @20 ' Number in Class' @40 'Percent of total (%)'; put @1 62 *'_'; footer: put @1 62 *'_'; put @1 "&ProjectPath.\Programs\Program1.sas"; 7

ods listing; ods rtf close; CONCLUSION It is my opinion that SAS programs can be developed in either Interactive mode or Batch mode and can produce the same end results. To achieve identical results in both modes you should remember to set all your options, templates, paths, libraries in one place and make them accessible in Interactive mode and in Batch mode. The AUTOEXEC.SAS file should contains all of your settings. If you use special options in your program, make sure to turn them off at the end of the program. You also should know that not all options and environmental variables are available in both modes and use them appropriately. One of the advantages of Interactive SAS mode is a user-friendly environment for development of a program with many tools for customizing your session. The great advantage of the Batch Mode is a considerable decrease in processing time. It is a good practice when you develop your program to make sure it is run in both Interactive mode and Batch mode and produce the same end result. It is important to save log and output files for audit documentation regardless of how you generate and execute your program. By using system options and environmental variables, you can easily control your output and generate the same output result. 8

REFERENCES Wei Cheng (2003), Build a SAS Development Environment under Windows SUGI, Paper 109-28 SAS Community website http://www.sascommunity.org/wiki/batch_processing_under_windows Modified on 31 August 2010, at 10:23 SAS Support Tech Notes http://support.sas.com/kb/8/681.html http://support.sas.com/kb/13/838.html Copyright 2007 SAS Institute Inc. SAS Help documentation: Using the SAS Editors under Windows CONTACT INFORMATION If you have any comments and questions regarding this paper, please contact: Irina Walsh ClinOps, LLC (Pacific Data Designs, LLC and ClinPro, Inc. are now ClinOps, LLC) 353 Sacramento Street, Suite 800 San Francisco, California 94111 (415) 776-0660 ext. 199 FAX (415) 776-0746 E-mail: Irina.Walsh@clinops.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. 9