Language Reference |
applies an IML module to its 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 arguments, argument1 through argumentn should be passed to APPLY where . 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 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 as follows:
R 2 rows 3 cols (numeric) 106 107 108 109 110 111
In the following 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 as follows:
A R 4 3 72 0 5 6 60 210
Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.