Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Language Reference

APPLY Function

applies an IML module to its arguments

APPLY( modname, argument1<, argument2,..., argument15>)

In the preceding statement,
modname
is the name of an existing module, supplied in quotes, as a matrix containing the module name, or an expression rendering the module name.

argument
is an argument passed to the module. You must have at least one argument. You can specify up to 15 arguments.

The APPLY function applies a user-defined IML module to each element of the argument matrix or matrices and returns a matrix of results. The first argument to APPLY is the name of the module. The module must already be defined before the APPLY function is executed. The module must be a function module, capable of returning a result.

The subsequent arguments to the APPLY function are the arguments passed to the module. They all must have the same dimension. If the module takes n arguments, argument1 through argumentn should be passed to APPLY where 1 \leq n \leq 15.The APPLY function effectively calls the module. The result has the same dimension as the input arguments, and each element of the result corresponds to the module applied to the corresponding elements of the argument matrices. The APPLY function can work on numeric as well as character arguments. For example, the following statements define module ABC and then call the APPLY function, with matrix A as an argument:

   start abc(x);
      r=x+100;
      return (r);
   finish abc;

   a={6 7 8,
      9 10 11};
   r=apply("ABC",a);
The result is
               R             2 rows      3 cols    (numeric)

                             106       107       108
                             109       110       111
In the next example, the statements define the module SWAP and call the APPLY function:
   start swap(a,b,c);
      r=a*b*c;
      a=b;
      if r<0 then return(0);
      return(r);
   finish swap;

   a={2  3, 4 5};
   b={4  3, 5 6};
   c={9 -1, 3 7};
   mod={swap};
   r=apply(mod,a,b,c);
   print a r;
The results are
                       A                   R
                       4         3        72         0
                       5         6        60       210

Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Top
Top

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