Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Understanding the Language

CALL Statements and Subroutines

CALL statements invoke a subroutine to perform calculations, operations, or a service. 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 matrix names, matrix literals, or expressions. If you specify several arguments, use commas to separate them. Also, when using arguments for output results, always use variable names rather than expressions or literals.

Creating Matrices with CALL Statements

Matrices are created whenever a CALL statement returns one or more result matrices. For example, the statement
   call eigen(val,vec,t);
returns two matrices (vectors), VAL and VEC, containing the eigenvalues and eigenvectors, respectively, of the symmetric matrix T.

You can program your own subroutine using the START and FINISH statements to define a module. You can then execute the module with a CALL statement or a RUN statement. For example, the following statements define a module named MYMOD that returns matrices containing 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,x);
Execution of the module statements create matrices S and L, containing the square roots and logs, respectively, of the elements of X.

Performing Services

You can use CALL statements to perform special services, such as managing SAS data sets or accessing the graphics system. For example, the statement
   call delete(mydata);
deletes the SAS data set named MYDATA.

The statements

   call gstart;
   call gopen;
   call gpoint(x,y);
   call gshow;
activate the graphics system (CALL GSTART), open a new graphics segment (CALL GOPEN), produce a scatter plot of points (CALL GPOINT), and display the graph (CALL GSHOW).

Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Top
Top

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