O'Reilly logo

SAS 9.4 Language Reference, 6th Edition by SAS Institute

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 28.2 Executing a Stored Compiled Program
Executable DATA
Step Program
DATA Step
Code Generator
Stored Compiled
DATA Step
Program
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 for Creating a Stored Compiled DATA Step Program
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 library.
password-option
assigns a password to a stored compiled DATA step program.
source-option
enables you to save or encrypt the source code.
For complete information about the DATA statement, see SAS Statements: Reference.
Process to Compile and Store a DATA Step Program
To compile and store a DATA step program, do the following:
1. Write, test, and debug the DATA step program that you want to store.
If you are reading external raw data files or if you write raw data to an external file,
use a fileref rather than the actual filename 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.
Creating a Stored Compiled DATA Step Program 681
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.
Note: If you move your application to another operating environment, you need to
recompile your source code and store your new compiled program.
Example: Creating a Stored Compiled DATA Step Program
The following example uses the information in the input SAS data set In.Sample 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
Stored.Sample, the DATA step that SAS stores.
libname in 'SAS-library';
libname stored 'SAS-library';
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;
Log 28.1 Partial SAS Log Identifying the Stored DATA Step Program
.
.
.
NOTE: DATA STEP program saved on file Stored.Sample.
NOTE: A stored DATA STEP program cannot run under a different operating
system.
NOTE: DATA statement used (Total process time):
real time 0.17 seconds
cpu time 0.01 seconds
682 Chapter 28 Stored Compiled DATA Step Programs

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required