Executing a Stored Compiled DATA Step Program


Syntax for Executing a Stored Compiled DATA Step Program

The syntax for executing a stored compiled DATA step program, optionally retrieving 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

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

    • submit this DATA step as a separate program

    • include it as part of a larger SAS program that can include other DATA and procedure (PROC) steps

    • point to different input and output SAS data sets each time you execute the stored program by using the REDIRECT statement.

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

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:

    • If the variable length attributes differ , the length of the variable in the source code data set determines the length of the variable in the redirected data set.

    • If extra variables are present in the redirected data sets, the stored program will continue to execute but the results of your program may not be what you expect.

    • If the variable type attributes are different, the stored program stops processing and an error message is sent to the SAS log.

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; 
Output 30.2: Partial SAS Log Showing the Source Code Generated by the DESCRIBE
start example
 .  .  .  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 
end example
 

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' on page 549. 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. Output 30.3 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; 
Output 30.3: Partial SAS Log Identifying the Redirected Output File
start example
 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 
end example
 



SAS 9.1 Language Reference. Concepts
SAS 9.1 Language Reference Concepts
ISBN: 1590471989
EAN: 2147483647
Year: 2004
Pages: 255

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net