Chapter Contents

Previous

Next
SAS Companion for the CMS Environment

Overview

REXX is a general purpose, high-level procedural language that is well known for combining powerful programming features with ease of use. REXX is also well known for its strengths as a macro language, most commonly with XEDIT. The SAS REXX macro facility enables you to use REXX as a macro language with SAS. This expands the programming possibilities available to you with SAS under CMS.

The REXX macro facility can be used to do the following things that the SAS macro facility can do:

You can also use the REXX macro facility to

To use the SAS REXX macro facility, write a REXX macro program and submit it from within a SAS session. A SAS REXX macro (SASMACRO) is a REXX program with a filetype of SASMACRO and a filename that you choose. A SASMACRO can contain SAS statements in addition to REXX code. When a SASMACRO is running, any instruction that REXX interprets as an external command is submitted to SAS for execution. For example, the following program, TRYIT SASMACRO (a version of which is shipped with SAS), submits a DATA step and a PROC step to SAS:

   /* TRYIT SASMACRO - a SAS REXX macro        */
   /* process arguments, establish defaults    */
parse arg dname argname .
if dname = '' then dname = 'a'
if argname = '' then argname = 'x'

   /* Pass a DATA step and PROC step into SAS  */
'data' dname';' argname'=1; run;'
'proc contents; run;'

exit     /* Return to SAS                      */

To run a SASMACRO, submit its CMS filename and any arguments as if it were a SAS statement. This effectively makes the SASMACRO an extension of the SAS language. A statement that invokes a SASMACRO may be placed anywhere in a SAS program. When SAS encounters a statement that it does not recognize, it passes the statement to the SAS REXX macro facility for execution. If there is no SASMACRO by the specified name, SAS flags the statement as invalid and prints an error message in the log.

Note:   A SASMACRO cannot have a name that is the same as a valid SAS statement or its abbreviation.  [cautionend]

To invoke the TRYIT SASMACRO example with two arguments, submit the following statement to SAS:

TRYIT A B;
This creates SAS data set A that contains one observation with one variable B, which has a value of 1.

A SASMACRO is invoked when SAS encounters it, just as any other global SAS statement in that location would be. A SASMACRO that is invoked within a DATA step is executed only one time, when the DATA step is compiled. It is not executed for each observation in the DATA step. Any SAS statements that are submitted from the SASMACRO are processed before subsequent statements are processed in the SAS program that invokes the SASMACRO.


Chapter Contents

Previous

Next

Top of Page

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