Creating and Executing Stored Compiled DATA Step Programs

Similar documents
SAS File Management. Improving Performance CHAPTER 37

Permission Program. Support for Version 6 Only. Allowing SAS/SHARE Client Access to SAS Libraries or Files CHAPTER 40

External Files. Definition CHAPTER 38

Chapter 3 Managing Results in Projects. Chapter Table of Contents

Data Set Options. Specify a data set option in parentheses after a SAS data set name. To specify several data set options, separate them with spaces.

SAS Catalogs. Definition. Catalog Names. Parts of a Catalog Name CHAPTER 32

SAS I/O Engines. Definition. Specifying a Different Engine. How Engines Work with SAS Files CHAPTER 36

SAS Support for TELNET on Windows

Optimizing System Performance

SAS Data Libraries. Definition CHAPTER 26

Chapter 25 PROC PARETO Statement. Chapter Table of Contents. OVERVIEW SYNTAX SummaryofOptions DictionaryofOptions...

Storing and Reusing Macros

Using Cross-Environment Data Access (CEDA)

UNIX Spawner Program. Starting the UNIX Spawner Program CHAPTER 36

Using Data Transfer Services

Chapter 6 Creating Reports. Chapter Table of Contents

Windows: SPX Access Method

OS/2: SPX Access Method

OS/390 Platform Examples

Introduction. LOCK Statement. CHAPTER 11 The LOCK Statement and the LOCK Command

APPENDIX 2 Customizing SAS/ASSIST Software

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

Data Representation. Variable Precision and Storage Information. Numeric Variables in the Alpha Environment CHAPTER 9

CHAPTER 5 Macintosh: TCP/IP Access Method

Formats. Formats Under UNIX. HEXw. format. $HEXw. format. Details CHAPTER 11

Chapter 14 Introduction to the FACTEX Procedure

UNIX Platform Error Messages

from the source host, use the FTP put command to copy a file from the source host to the target host.

Using MDP Extensions. What Is the Multidimensional Data Provider? CHAPTER 3

Locking SAS Data Objects

Introduction to MDDBs

Using the SQL Editor. Overview CHAPTER 11

Informats. Informats Under UNIX. HEXw. informat. $HEXw. informat. Details CHAPTER 13

QUEST Procedure Reference

CHAPTER 7 Examples of Combining Compute Services and Data Transfer Services

Graphics. Chapter Overview CHAPTER 4

Routing the SAS Log and SAS Procedure Output

Examples That Use Remote Objecting

DBLOAD Procedure Reference

CHAPTER 7 Using Other SAS Software Products

What Is a Communications Access Method? CHAPTER 1 Using Communications Access Methods

OpenVMS Operating Environment

Chapter 23 Introduction to the OPTEX Procedure

Chapter 13 Multivariate Techniques. Chapter Table of Contents

APPENDIX 4 Migrating from QMF to SAS/ ASSIST Software. Each of these steps can be executed independently.

The SERVER Procedure. Introduction. Syntax CHAPTER 8

Chapter 23 Animating Graphs. Chapter Table of Contents ANIMATING SELECTION OF OBSERVATIONS ANIMATING SELECTED GRAPHS...347

Using Dynamic Data Exchange

Using Unnamed and Named Pipes

Chapter 9 Selected Examples. Queues with Reneging

The EXPLODE Procedure

DATA Step Debugger APPENDIX 3

Chapter 15 Mixed Models. Chapter Table of Contents. Introduction Split Plot Experiment Clustered Data References...

SAS/ASSIST Software Setup

CHAPTER 13 Importing and Exporting External Data

Using SAS Files. Introduction CHAPTER 5

Tasks Menu Reference. Introduction. Data Management APPENDIX 1

Chapter 28 INSET Statement. Chapter Table of Contents

Performance Considerations

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

Chapter 7 File Access. Chapter Table of Contents

Choosing the Right Procedure

The GREMOVE Procedure

Customizing Your SAS Session

The GTESTIT Procedure

Batch Importing. Overview CHAPTER 4

SAS/FSP 9.2. Procedures Guide

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

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

Chapter 2 User Interface Features. networks Window. Drawing Panel

Overview. CHAPTER 2 Using the SAS System and SAS/ ASSIST Software

Changes and Enhancements

Routing Output. Producing Output with SAS Software CHAPTER 6

Alternative ODS HTML Statements for Running Examples in Different Operating Environments

SAS Component Language (SCL) Interface to Agent Services

SAS. IT Service Level Management 2.1: Migration Documentation

SAS Web Infrastructure Kit 1.0. Overview

Moving and Accessing SAS. 9.1 Files

This chapter is recommended primarily for server administrators.

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

SAS Drug Development. SAS Macro API 1.3 User s Guide

CV2ODBC Procedure. Overview. CV2ODBC Procedure Syntax APPENDIX 4

SAS Strategy Management 5.2 Batch Maintenance Facility

Introduction. Getting Started with the Macro Facility CHAPTER 1

Chapter 27 Saving and Printing Graphics

Moving and Accessing SAS 9.2 Files

SCL Arrays. Introduction. Declaring Arrays CHAPTER 4

SYSTEM 2000 Essentials

Enterprise Miner Software: Changes and Enhancements, Release 4.1

SAS. Installation Guide Fifth Edition Intelligence Platform

Licensing SAS DataFlux Products

The GSLIDE Procedure. Overview. About Text Slides CHAPTER 27

SAS Clinical Data Integration Server 2.1

SAS Workflow Manager 2.2: Administrator s Guide

SAS/ACCESS Interface to R/3

Procedures. Calls any BMDP program to analyze data in a SAS data set

Changes and Enhancements

SAS/ACCESS Data Set Options

The GANNO Procedure. Overview CHAPTER 12

The GIMPORT Procedure

Transcription:

465 CHAPTER 30 Creating and Executing Stored Compiled DATA Step Programs Definition 465 Uses for Stored Compiled DATA Step Programs 465 Restrictions and Requirements 466 How SAS Processes Stored Compiled DATA Step Programs 466 Creating a Stored Compiled DATA Step Program 467 Syntax 467 Process 467 Example: Creating a Stored Compiled DATA Step Program 468 Executing a Stored Compiled DATA Step Program 468 Syntax 468 Process 469 Using Global Statements 470 Redirecting Output 470 Printing the Source Code of a Stored Compiled DATA Step Program 470 Example: Executing a Stored Compiled DATA Step Program 471 Differences between Stored Compiled DATA Step Programs and DATA Step Views 472 Examples 472 Example 1: Quality Control Application 472 Definition A stored compiled DATA step program is a SAS file that contains a DATA step program that has been compiled and then stored in a SAS data library You can execute stored compiled programs as needed, without having to recompile them Stored compiled DATA step programs are of member type PROGRAM Note: Stored compiled programs are available for DATA step applications only Your stored programs can contain all SAS language elements except global statements If you do include global statements in your source program, SAS stores the compiled program but not the global statements, and does not display a warning message in the SAS log 4 Uses for Stored Compiled DATA Step Programs The primary use of stored compiled DATA step programs is for executing production jobs The advantage of using these DATA step programs is that you can execute them as needed without investing the resources required for repeated compilation The savings are especially significant if the DATA step contains many statements If you install a new version of SAS, you do not need to recompile your source code

466 Restrictions and Requirements 4 Chapter 30 Restrictions and Requirements The following restrictions and requirements apply for using stored compiled DATA step programs: 3 Stored compiled DATA step programs are available for DATA step applications only 3 Stored compiled DATA step program cannot contain global statements If you do include global statements such as FILENAME, FOOTNOTE, LIBNAME, OPTIONS, and TITLE in your source program, SAS stores the compiled program but not the global statements SAS does not display a warning message in the SAS log 3 SAS does not store raw data in the compiled program Operating Environment Information: You cannot move a compiled program to an operating environment that has an incompatible machine architecture You must, instead, recompile your source code and store your new compiled program You can, however, move your compiled program to a different host machine that has a compatible architecture 4 How SAS Processes Stored Compiled DATA Step Programs You first compile the SAS source program and store the compiled code Then you execute the compiled code, redirecting the input and output as necessary SAS processes the DATA step through the compilation phase and then stores an intermediate code representation of the program and associated data tables in a SAS file SAS processes the intermediate code when it executes the stored program The following figure shows the process for creating a stored compiled DATA step program Figure 301 Creating a Stored Compiled Program DATA Step Source Code DATA Step Compiler Stored Compiled DATA Step Program When SAS executes the stored program, it resolves the intermediate code produced by the compiler and generates the executable machine code for that operating environment The following figure shows the process for executing a stored compiled DATA step program Figure 302 Executing a Stored Compiled Program Stored Compiled DATA Step Program DATA Step Code Generator Executable DATA Step Program

Creating and Executing Stored Compiled DATA Step Programs 4 Process 467 To move, copy, rename, or delete stored programs, use the DATASETS procedure or the utility windows in your windowing environment Creating a Stored Compiled DATA Step Program Syntax The syntax for creating a stored compiled DATA step program is as follows: DATA data-set-name(s) / PGM=stored-program-name <(<password-option><source=source-option>)>; where data-set-name specifies a valid SAS name for the output data set created by the source program The name can be a one-level name or a two-level name You can specify more than one data set name in the DATA statement stored-program-name specifies a valid SAS name for the SAS file containing the stored program The name can be a one-level name, but it is usually a two-level name Stored programs are assigned the member type PROGRAM in the SAS data library password-option assigns a password to a stored compiled DATA step program source-option allows you to save or encrypt the source code For complete information about the DATA statement, see SAS Language Reference: Dictionary Process To compile and store a DATA step program, do the following: 1 Write, test, and debug the DATA step program you want to store If you are reading external raw data files or if you output raw data to an external file, use a fileref rather than the actual file name in your INFILE and FILE statements so that you can redirect your input and output when the stored program executes 2 When the program runs correctly, submit it using the PGM= option in the DATA statement The PGM= option tells SAS to compile, but not execute, the program and to store the compiled code in the SAS file named in the option SAS sends a message to the log when the program is stored Note: The default SOURCE=SAVE or SOURCE=ENCRYPT options automatically save your source code 4 Note: If you move your application to another operating environment, you need to recompile your source code and store your new compiled program 4

468 Example: Creating a Stored Compiled DATA Step Program 4 Chapter 30 Example: Creating a Stored Compiled DATA Step Program The following example uses the information in the input SAS data set INSAMPLE to assign a plant type based on a plant code Note that the global LIBNAME statements are necessary to identify the storage location for your files, but are not part of STOREDSAMPLE, the DATA step that SAS stores libname in SAS-data-library ; libname stored SAS-data-library ; data outsample / pgm=storedsample; set insample; if code = 1 then Type= Perennial ; number+4; else if code = 2 then Type= Annual ; number+10; else Type= ERROR ; Number=0; Output 301 Partial SAS Log Identifying the Stored DATA Step Program NOTE: DATA STEP program saved on file STOREDSAMPLE NOTE: A stored DATA STEP program cannot run under a different operating system NOTE: DATA statement used: real time 114 seconds cpu time 012 seconds Executing a Stored Compiled DATA Step Program Syntax The syntax for executing a stored compiled DATA step program, optionally retreiving source code, and optionally redirecting input or output, is as follows: global SAS statements DATA PGM=stored-program-name <(password-option)>;

Creating and Executing Stored Compiled DATA Step Programs 4 Process 469 <DESCRIBE;> <REDIRECT INPUT OUTPUT old-name-1 = new-name-1< old-name-n = new-name-n>;> <EXECUTE;> where global SAS statements specifies any global SAS statements that are needed by the program when it executes, such as a FILENAME or a LIBNAME statement that points to input files or routes output stored-program-name specifies a valid SAS name for the SAS file containing the stored program The name can be a one-level name or a two-level name password-option specifies a password that you use to access the stored compiled DATA step program DESCRIBE is a SAS statement that retrieves source code from a stored compiled DATA step program or a DATA step view INPUT OUTPUT specifies whether you are redirecting input or output data sets When you specify INPUT, the REDIRECT statement associates the name of the input data set in the source program with the name of another SAS data set When you specify OUTPUT, the REDIRECT statement associates the name of the output data set with the name of another SAS data set old-name specifies the name of the input or output data set in the source program new-name specifies the name of the input or output data set that you want SAS to process for the current execution EXECUTE is a SAS statement that executes a stored compiled DATA step program For complete information about the DATA statement, see SAS Language Reference: Dictionary Process To execute a stored compiled DATA step program, follow these steps: 1 Write a DATA step for each execution of the stored program In this DATA step, specify the name of the stored program in the PGM= option of the DATA statement and include an optional password You can 3 submit this DATA step as a separate program 3 include it as part of a larger SAS program that can include other DATA and procedure (PROC) steps 3 point to different input and output SAS data sets each time you execute the stored program by using the REDIRECT statement 2 Submit the DATA steps Be sure to end each one with a RUN statement or other step boundary

470 Using Global Statements 4 Chapter 30 Using Global Statements You can use global SAS statements such as FILENAME or LIBNAME when you store or execute a stored compiled DATA step program However, the global statements that you use to compile and store a DATA step program are not stored with the DATA step code Redirecting Output You can redirect external files using filerefs You can use the REDIRECT statement for renaming input and output SAS data sets You can use the REDIRECT statement to redirect input and output data to data sets you specify Note that the REDIRECT statement is available only for use with stored compiled DATA step programs Note: To redirect input and output stored in external files, include a FILENAME statement at execution time to associate the fileref in the source program with different external files 4 CAUTION: Use caution when you redirect input data sets The number and attributes of variables in the input SAS data sets that you read with the REDIRECT statement should match those of the input data sets in the SET, MERGE, MODIFY, or UPDATE statements of the source code If they do not match, the following occurs: 3 If the variable length attributes differ, the length of the variable in the source code data set determines the length of the variable in the redirected data set 3 If extra variables are present in the redirected data sets, the stored program will continue to execute but the results of your program may not be what you expect 3 If the variable type attributes are different, the stored program stops processing and an error message is sent to the SAS log 4 Printing the Source Code of a Stored Compiled DATA Step Program If you use both the DESCRIBE and the EXECUTE statements when you execute a stored compiled DATA step program, SAS writes the source code to the log The following example executes a stored compiled DATA step program The DESCRIBE statement in the program writes the source code to the SAS log data pgm=storedsample; describe; execute;

Creating and Executing Stored Compiled DATA Step Programs 4 Example: Executing a Stored Compiled DATA Step Program 471 Output 302 Statement Partial SAS Log Showing the Source Code Generated by the DESCRIBE 26 27 data pgm=storedsample; 28 describe; 29 execute; 30 NOTE: DATA step stored program STOREDSAMPLE is defined as: data outsample / pgm=storedsample; set insample; if code = 1 then Type= Perennial ; number+4; else if code = 2 then Type= Annual ; number+10; else Type= ERROR ; Number=0; NOTE: DATA STEP program loaded from file STOREDSAMPLE NOTE: There were 7 observations read from the dataset INSAMPLE NOTE: The data set OUTSAMPLE has 7 observations and 4 variables NOTE: DATA statement used: real time 080 seconds cpu time 015 seconds For more information about the DESCRIBE statement, see SAS Language Reference: Dictionary Example: Executing a Stored Compiled DATA Step Program The following DATA step executes the stored program STOREDSAMPLE created in Example: Creating a Stored Compiled DATA Step Program on page 468 The REDIRECT statement specifies the source of the input data as BASESAMPLE The output from this execution of the program is redirected and stored in a data set named TOTALSSAMPLE Output 303 on page 472 shows part of the SAS log libname in SAS-data-library ; libname base SAS-data-library ; libname totals SAS-data-library ; libname stored SAS-data-library ; data pgm=storedsample; redirect input insample=basesample;

472 Differences between Stored Compiled DATA Step Programs and DATA Step Views 4 Chapter 30 redirect output outsample=totalssample; Output 303 Partial SAS Log Identifying the Redirected Output File cpu time 000 seconds 6 7 data pgm=storedsample; 8 redirect input insample=basesample; 9 redirect output outsample=totalssample; 10 NOTE: DATA STEP program loaded from file STOREDSAMPLE NOTE: The data set TOTALSSAMPLE has 7 observations and 4 variables NOTE: DATA statement used: real time 067 seconds Differences between Stored Compiled DATA Step Programs and DATA Step Views Stored compiled DATA step programs and DATA step views are similar in function They both store DATA step programs that can retrieve and process data stored in other files Both have the same restrictions and requirements (see Restrictions and Requirements on page 466) For information about DATA step views, see Chapter 29, SAS Data Views, on page 455 Stored compiled DATA step programs and DATA step views differ in the following ways: 3 A stored compiled DATA step program is explicitly executed when it is specified by the PGM= option on a DATA statement The stored compiled DATA step is used primarily in production jobs 3 A DATA step view is implicitly executed when the view is referenced as an input data set by another DATA or procedure (PROC) step Its main purpose is to provide data one record at a time to the invoking procedure or DATA step 3 You can use the REDIRECT statement when you execute a stored compiled DATA step You can not use this statement with DATA step views Examples Example 1: Quality Control Application This example illustrates how to use a stored compiled DATA step program for a simple quality control application This application processes several raw data files The source program uses the fileref DAILY in the INFILE statement Each DATA step that is used to execute the stored program can include a FILENAME statement to associate the fileref DAILY with a different external file The following statements compile and store the program:

Creating and Executing Stored Compiled DATA Step Programs 4 Example 1: Quality Control Application 473 libname stored SAS-data-library-1 ; data flaws / pgm=storedflaws; length Station $ 15; infile daily; input Station $ Shift $ Employee $ NumberOfFlaws; TotalNumber + NumberOfFlaws; The following statements execute the stored compiled program, redirect the output, and print the results: libname stored SAS-data-library-1 ; libname testlib SAS-data-library-2 ; data pgm=storedflaws; redirect output flaws=testlibdaily; proc print data=testlibdaily; title Quality Control Report ; Output 304 Quality Control Application Output Quality Control Report 1 Number Total Obs Station Shift Employee OfFlaws Number 1 Cambridge 1 Lin 3 3 2 Northampton 1 Kay 0 3 3 Springfiled 2 Sam 9 12 Note that you can use the TITLE statement when you execute a stored compiled DATA step program or when you print the results

474 Example 1: Quality Control Application 4 Chapter 30

The correct bibliographic citation for this manual is as follows: SAS Institute Inc, SAS Language Reference: Concepts, Cary, NC: SAS Institute Inc, 1999 554 pages SAS Language Reference: Concepts Copyright 1999 SAS Institute Inc, Cary, NC, USA ISBN 1 58025 441 1 All rights reserved Printed in the United States of America No part of this publication may be reproduced, stored in a retrieval system, or transmitted, by any form or by any means, electronic, mechanical, photocopying, or otherwise, without the prior written permission of the publisher, SAS Institute, Inc US Government Restricted Rights Notice Use, duplication, or disclosure of the software by the government is subject to restrictions as set forth in FAR 52227 19 Commercial Computer Software-Restricted Rights (June 1987) SAS Institute Inc, SAS Campus Drive, Cary, North Carolina 27513 1st printing, November 1999 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 IBM, ACF/VTAM, AIX, APPN, MVS/ESA, OS/2, OS/390, VM/ESA, and VTAM are registered trademarks or trademarks of International Business Machines Corporation indicates USA registration Other brand and product names are registered trademarks or trademarks of their respective companies The Institute is a private company devoted to the support and further development of its software and related services