Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Introduction to SAS/IML Software

An Introductory Interactive Session

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 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

Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Top
Top

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