Introduction to SAS/IML Software |
Here is a simple introductory session that uses SAS/IML software to estimate the square root of a number, accurate to three decimal places. In this session, you define a function module named APPROX to perform the calculations and return the approximation. You then call APPROX to estimate the square root of several numbers given in a matrix literal (enclosed in braces), and you print the results.
Throughout the session, the right angle brackets (>) indicate statements that you submit; responses from PROC IML follow.
> proc iml; /* begin IML session */ IML Ready > start approx(x); /* begin module */ > y=1; /* initialize y */ > do until(w<1e-3); /* begin DO loop */ > z=y; /* set z=y */ > y=.5#(z+x/z); /* estimate square root */ > w=abs(y-z); /* compute change in estimate */ > end; /* end DO loop */ > return(y); /* return approximation */ > finish approx; /* end module */ NOTE: Module APPROX defined. > t=approx({3,5,7,9}); /* call function APPROX */ > print t; /* print matrix */ T 1.7320508 2.236068 2.6457513 3 > quit; Exiting IML
Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.