Appendix D. Modules for Compatability with SAS/IML 9.22

Contents

  • D.1 Overview of SAS/IML 9.22 Modules 435

  • D.2 The Mean Module 435

  • D.3 The Var Module 436

  • D.4 The Qntl Module 436

D.1 Overview of SAS/IML 9.22 Modules

This book presents a few examples that use functions that were introduced in SAS/IML 9.22. If you have not yet upgraded to SAS/IML 9.22 or SAS 9.3, you might want to define and run the following modules, which implement portions of the functionality of the MEAN and VAR functions and the QNTL subroutine.

The function definitions will fail if you are running SAS/IML 9.22 or later because the SAS/IML language does not permit you to redefine built-in functions.

D.2 The Mean Module

/* Mean: return sample mean of each column of a data matrix */
/* For this module
 *    x     is a matrix that contains the data
 */
start Mean(x);
   mean = x[:,];
   return ( mean );
finish;

D.3 The Var Module

/* Var: return sample variance of each column of a data matrix */
/* For this module
 *    x is a matrix that contains the data
 */
start Var(x);
   mean = x[:,];
   countn = j(1, ncol(x));                        /* allocate vector for counts */
   do i = 1 to ncol(x);                           /* count nonmissing values    */
      countn[i] = sum(x[,i]^=.);                  /* in each column             */
   end;
   var = (x-mean)[##,] / (countn-1);
   return ( var );
finish;

D.4 The Qntl Module

/* Qntl: compute quantiles (Defn. 5 from the UNIVARIATE doc) */
/* For this module
 *    q   upon return, q contains the specified quantiles of
 *        the data.
 *    x   is a matrix. The module computes quantiles for each column.
 *    p   specifies the quantiles. For example, 0.5 specifies the
 *        median, whereas {0.25 0.75} specifies the first and
 *        third quartiles.
 * This module does not handle missing values in the data.
 */
start Qntl(q, x, p);                     /* definition 5 from UNIVARIATE doc */
   n = nrow(x);                          /* assume nonmissing data           */
   q = j(ncol(p), ncol(x));
   do j = 1 to ncol(x);
      y = x[,j];
      call sort(y,1);
      do i = 1 to ncol(p);
         k = n*p[i];                     /* position in ordered data         */
         k1 = int(k);                    /* indices into ordered data        */
         k2 = k1 + 1;
         g =  k - k1;
         if g>0 then
            q[i,j] = y[k2];              /* return a data value              */
         else                            /* average adjacent data            */
            q[i,j] = (y[k1]+y[k2])/2;
      end;
   end;
finish;
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset