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