Programming Statements |
You can pass expressions and subscripted matrices as arguments to a module, but it is important to understand the way IML evaluates the expressions and passes results to the module. Expressions are evaluated, and the evaluated values are stored in temporary variables. Similarly, submatrices are created from subscripted variables and stored in temporary variables. The temporary variables are passed to the module while the original matrix remains intact. Notice that, in the example that follows, the matrix X remains intact. You might expect X to contain the squared values of Y.
> proc iml; > reset printall; > start square(a,b); > a=b##2; > finish; > /* create two data matrices */ > x={5 9 }; X 1 row 2 cols (numeric) 5 9 > y={10 4}; Y 1 row 2 cols (numeric) 10 4 > /* pass matrices to module element-by-element */ > do i=1 to 2; > run square(x[i],y[i]); > end; > /* RESET PRINTALL prints all intermediate results */
I 1 row 1 col (numeric) 1 #TEM1002 1 row 1 col (numeric) 10 #TEM1001 1 row 1 col (numeric) 5 A 1 row 1 col (numeric) 100 #TEM1002 1 row 1 col (numeric) 4 #TEM1001 1 row 1 col (numeric) 9 A 1 row 1 col (numeric) 16 > /* show X and Y are unchanged */ > print x y; X Y 5 9 10 4The symbol X remains unchanged because the temporary variables that you generally do not see are changed. Note that IML properly warns you of any such instances in which your results might be lost to the temporary variables.
Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.