Chapter Contents Previous Next
 Understanding the Language

Functions

The general form of a function is

result = FUNCTION ( arguments);
where arguments can be matrix names, matrix literals, or expressions. Functions always return a single result (whereas subroutines can return multiple results or no result). If a function returns a character result, the matrix to hold the result is allocated with a string length equal to the longest element, and all shorter elements are padded with blanks.

Categories of Functions

Functions fall into the following six categories:
 matrix inquiry functions return information about a matrix. For example, the ANY function returns a value of 1 if any of the elements of the argument matrix are nonzero. scalar functions operate on each element of the matrix argument. For example, the ABS function returns a matrix with elements that are the absolute values of the corresponding elements of the argument matrix. summary functions return summary statistics based on all elements of the matrix argument. For example, the SSQ function returns the sum of squares of all elements of the argument matrix. matrix arithmetic functions perform matrix algebraic operations on the argument. For example, the TRACE function returns the trace of the argument matrix.
 matrix reshaping functions manipulate the matrix argument and return a reshaped matrix. For example, the DIAG function returns a matrix with diagonal elements that are equal to the diagonal elements of a square argument matrix. All off-diagonal elements are zero. linear algebra and statistical functions perform linear algebraic functions on the matrix argument. For example, the GINV function returns the matrix that is the generalized inverse of the argument matrix.

Exceptions to the SAS DATA Step

SAS/IML software supports most functions supported in the SAS DATA step. These functions all accept matrix arguments, and the result has the same dimension as the argument. (See Appendix 1 for a list of these functions.) The following functions are not supported by SAS/IML software:

 DIFn HBOUND LAGn PUT DIM INPUT LBOUND
The following functions are implemented differently in SAS/IML software. (See Chapter 17, "Language Reference," for descriptions.)

 MAX RANK SOUND SUBSTR MIN REPEAT SSQ SUM

The random number functions, UNIFORM and NORMAL, are built-in and produce the same streams as the RANUNI and RANNOR functions, respectively, of the DATA step. For example, to create a 10 ×1 vector of random numbers, use

```   x=uniform(repeat(0,10,1));
```
Also, SAS/IML software does not support the OF clause of the SAS DATA step. For example, the statement
```   a=mean(of x1-x10); /* invalid in IML */
```
cannot be interpreted properly in IML. The term (X1-X10) would be interpreted as subtraction of the two matrix arguments rather than its DATA step meaning, "X1 through X10."

 Chapter Contents Previous Next Top