Subroutines (also called “CALL statements”) perform calculations, operations, or interact with the SAS sytem. CALL statements are often used in place of functions when the operation returns multiple results or, in some cases, no result. The general form of the CALL statement is
CALL SUBROUTINE
(arguments) ;
where arguments can be a list of matrix names, matrix literals, or expressions. If you specify several arguments, use commas to separate them. When using output arguments that are computed by a subroutine, always use variable names instead of expressions or literals.
Matrices are created whenever a CALL statement returns one or more result matrices. For example, the following statement returns
two matrices (vectors), val
and vec
, that contain the eigenvalues and eigenvectors, respectively, of the matrix A
:
call eigen(val,vec,A);
You can program your own subroutine by using the START and FINISH statements to define a module. You can then execute the module with a CALL or RUN statement. For example, the following statements define a module named MyMod which returns matrices that contain the square root and log of each element of the argument matrix:
start MyMod(a,b,c); a=sqrt(c); b=log(c); finish; run MyMod(S,L,{1 2 4 9});
Execution of the module statements creates matrices S
and L
which contain the square roots and natural logs, respectively, of the elements of the third argument.
You can use CALL statements to manage SAS data sets or to access the PROC IML graphics system. For example, the following
statement deletes the SAS data set named MyData
:
call delete(MyData);
The following statements activate the graphics system and produce a crude scatter plot:
x = 0:100; y = 50 + 50*sin(6.28*x/100); call gstart; /* activate the graphics system */ call gopen; /* open a new graphics segment */ call gpoint(x,y); /* plot the points */ call gshow; /* display the graph */ call gclose; /* close the graphics segment */
SAS/IML Studio, which is distributed as part of SAS/IML software, contains graphics that are easier to use and more powerful than the older GSTART/GCLOSE graphics in PROC IML. See the SAS/IML Studio User's Guide for a description of the graphs in SAS/IML Studio.