Chapter Contents

Previous

Next

Executing a Stored Compiled DATA Step Program


Syntax

The syntax for executing a stored compiled DATA step program, optionally retreiving source code, and optionally 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.

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 SAS Language Reference: Dictionary.


Process

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

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

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:

  [cautionend]

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;

Partial SAS Log Showing the Source Code Generated by the DESCRIBE Statement
    
.
.   
.      
26   
27   data pgm=stored.sample;
28      describe;
29      execute;
30   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 dataset IN.SAMPLE.
NOTE: The data set OUT.SAMPLE has 7 observations and 4 variables.
NOTE: DATA statement used:
      real time           0.80 seconds
      cpu time            0.15 seconds
      

For more information about the DESCRIBE statement, see SAS Language Reference: Dictionary.


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. The REDIRECT statement specifies the source of the input data as BASE.SAMPLE. The output from this execution of the program is redirected and stored in a data set named TOTALS.SAMPLE. Partial SAS Log Identifying the Redirected Output File shows part of the SAS log.

libname in 'SAS-data-library'; 
libname base 'SAS-data-library'; 
libname totals 'SAS-data-library'; 
libname stored 'SAS-data-library';  
data pgm=stored.sample;    
   redirect input in.sample=base.sample;    
   redirect output out.sample=totals.sample; 
run; 

Partial SAS Log Identifying the Redirected Output File
      cpu time            0.00 seconds
.
.     
.
6   
7   data pgm=stored.sample;
8      redirect input in.sample=base.sample;
9      redirect output out.sample=totals.sample;
10   run;
NOTE: DATA STEP program loaded from file STORED.SAMPLE.
NOTE: The data set TOTALS.SAMPLE has 7 observations and 4 variables.
NOTE: DATA statement used:
      real time           0.67 seconds


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.