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 data library.
password-option
assigns a password to a stored compiled DATA step program.
source-option
allows you to save or encrypt the source code.
For complete information about the DATA statement, see SAS Language Reference: Dictionary .
To compile and store a DATA step program, do the following:
Write, test, and debug the DATA step program you want to store.
If you are reading external raw data files or if you output raw data to an external file, use a fileref rather than the actual file name in your INFILE and FILE statements so that you can redirect your input and output when the stored program executes.
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. |
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-data-library '; libname stored ' SAS-data-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;
. . . 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