Previous Page | Next Page

The FCMP Procedure

SUBROUTINE Statement


Declares (creates) an independent computational block of code that you can call using a CALL statement.
SUBROUTINE subroutine-name (argument-1, ..., argument-n) <VARARGS> <KIND | GROUP='string'>;
OUTARGS out-argument-1, ..., out-argument-n;
... more-program-statements ...
ENDSUB;

Arguments

subroutine-name

specifies the name of a subroutine.

argument

specifies one or more arguments for the subroutine. Character arguments are specified by placing a dollar sign ($) after the argument name. In the following example,

subroutine mysub(arg1, arg2 $, arg3, arg4 $);
arg1 and arg3 are numeric arguments, and arg2 and arg4 are character arguments.
VARARGS

specifies that the subroutine supports a variable number of arguments. If you specify VARARGS, then the last argument in the subroutine must be an array.

OUTARGS

specifies arguments from the argument list that the subroutine should update.

KIND | GROUP='string'

specifies a collection of items that have specific attributes.

out-argument

specifies arguments from the argument list that you want the subroutine to update.


Details

The SUBROUTINE statement enables you to declare (create) an independent computational block of code that you can call with a CALL statement. The definition of a subroutine begins with the SUBROUTINE statement and ends with an ENDSUB statement. You can use the OUTARGS statement in a SUBROUTINE statement to specify arguments from the argument list that the subroutine should update.


Examples

The following is an example of the SUBROUTINE statement:

proc fcmp outlib=sasuser.funcs.temp;
subroutine inverse(in, inv) group="generic";
   outargs inv;
   if in=0 then inv=.;
   else inv=1/in;
endsub;

options cmplib=sasuser.funcs;
data _null_;
   x = 5;
   call inverse(x, y);
   put x= y=;
run;

SAS writes the following output to the log:

x=5 y=0.2

Previous Page | Next Page | Top of Page