Executing a Stored Compiled DATA Step Program
Syntax for Executing a Stored Compiled DATA Step Program
The syntax for executing a stored compiled DATA step program, retrieving source code,
and redirecting input or output, is as follows:
global SAS statements
DATA PGM=stored-program-name <(password-option)>;
<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.
Note: To DESCRIBE a password-protected DATA step program, you must specify
its password. If the program has more than one password, you must specify the
most restrictive password (with ALTER being the most restrictive and READ the
least restrictive). For more information, see “DESCRIBE Statement” in SAS
DATA Step Statements: Reference.
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 “DATA Statement” in SAS
DATA Step Statements: Reference.
Executing a Stored Compiled DATA Step Program 689
Process to Execute a Stored Compiled DATA Step Program
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 do any of the following tasks:
Submit this DATA step as a separate program.
Include it as part of a larger SAS program that can include other DATA and
procedure (PROC) steps.
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.
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.
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:
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.
If extra variables are present in the redirected data sets, the stored program stops
processing, and an error message is sent to the SAS log.
If the variable type attributes are different, the stored program stops processing, and
an error message is sent to the SAS log.
690 Chapter 30 Stored Compiled DATA Step Programs

Get SAS 9.4 Language Reference, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.