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
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
Statements: Reference.
Executing a Stored Compiled DATA Step Program 683
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.
684 Chapter 28 Stored Compiled DATA Step Programs
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=stored.sample;
describe;
execute;
run;
Log 28.2 Partial SAS Log Showing the Source Code Generated by the DESCRIBE
Statement
.
.
.
190 data pgm=stored.sample;
191 describe;
192 execute;
193 run;
NOTE: DATA step stored program Stored.Sample is defined as:
data out.sample / pgm=stored.sample;
set in.sample;
if code = 1 then
do;
Type='Perennial';
number+4;
end;
else
if code = 2 then
do;
Type='Annual';
number+10;
end;
else
do;
Type='ERROR';
Number=0;
end;
run;
NOTE: DATA STEP program loaded from file Stored.Sample.
NOTE: There were 7 observations read from the data set In.Sample.
NOTE: The data set OUT.SAMPLE has 7 observations and 4 variables.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.00 seconds
For more information about the DESCRIBE statement, see SAS Statements: Reference.
Example: Executing a Stored Compiled DATA Step Program
The following DATA step executes the stored program Stored.Sample created in
“Example: Creating a Stored Compiled DATA Step Program” on page 682. The
REDIRECT statement specifies the source of the input data as BASE.SAMPLE. The
Executing a Stored Compiled DATA Step Program 685
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.172.115