Previous Page | Next Page

Stored Compiled DATA Step Programs

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>)>;



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.


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.


assigns a password to a stored compiled DATA step program.


enables 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

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 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.

    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.  [cautionend]

Note:   If you move your application to another operating environment, you need to recompile your source code and store your new compiled program.   [cautionend]

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
   if code = 2 then

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:
      real time           1.14 seconds
      cpu time            0.12 seconds

Previous Page | Next Page | Top of Page