Thursday, December 24, 2015

Calculating Kappa with SAS® by John Uebersax

Calculating Kappa with SAS® by John Uebersa

Counting the number of AEs and the numbers of subjects with AEs using proc SQL

/*******************************************************************/
/*   Compare the programs below and see what the differences are   */
/*******************************************************************/

select bsystxt, count(ptno)  
          from bios.ae 
          group by bsystxt;

WHO Body System Text                                        
 ------------------------------------------------------------
 BODY AS A WHOLE - GENERAL DISORDERS                        3
 CENTR & PERIPH NERVOUS SYSTEM DISORDERS                   17
 GASTRO-INTESTINAL SYSTEM DISORDERS                        31
 HEARING AND VESTIBULAR DISORDERS                           1
 PSYCHIATRIC DISORDERS                                      7
 SKIN AND APPENDAGES DISORDERS                              7
 URINARY SYSTEM DISORDERS                                   1
 VASCULAR (EXTRACARDIAC) DISORDERS                          4
 VISION DISORDERS                                           1



select bsystxt,count(distinct ptno)
   from bios.ae
   group by bsystxt;


 WHO Body System Text                                        
 ------------------------------------------------------------
 BODY AS A WHOLE - GENERAL DISORDERS                        2
 CENTR & PERIPH NERVOUS SYSTEM DISORDERS                    5
 GASTRO-INTESTINAL SYSTEM DISORDERS                         6
 HEARING AND VESTIBULAR DISORDERS                           1
 PSYCHIATRIC DISORDERS                                      3
 SKIN AND APPENDAGES DISORDERS                              7
 URINARY SYSTEM DISORDERS                                   1
 VASCULAR (EXTRACARDIAC) DISORDERS                          4
 VISION DISORDERS                                           1

Calculating AUC using cubic spline interpolation or trapezoid rule

/************************************************************************
    PURPOSE:
    This program uses PROC EXPAND to calculate the approximate area under
    the curve for some sample data.  The sample data should consist of
    (x,y) pairs.

   DETAILS:
    For this example, the sample data is generated from a high degree
    polynomial. PROC EXPAND is then used to compute the approximate area
    under the curve using each of the following methods:

       a.  Cubic Spline interpolation.
       b.  Trapezoid rule.

    The exact area, given by the definite integral, is calculated
    for the polynomial curve in order to assess the precision of the
    approximations.


************************************************************************/

%let lower=-2;
%let upper=1;
%let interval=0.2;

* generate some data according to a high order polynomial;
data kvm;
 do x=&lower to &upper by &interval;
  y=15+(x-2)*(x-1.5)*(x-1)*(x-.5)*x*(x+.5)*(x+1)*(x+1.5)*(x+2);
  output;
 end;

proc sort;
 by x;

/* PROC EXPAND will include a contribution for the last interval.  For
   an accurate approximation to the integral, we need to make sure that
   this last contribution is negligible.  So we'll append an additional
   x value which is extremely close to the last x value.  Of course, the
   two Y values will be identical.  But the result is that the last
   interval is extremely short, so any contribution to the integral
   approximation is negligible.
*/

data one;
 set kvm end=eof;
 output;
 if eof then do;
   x=x+(1e-10);
   output;
 end;
run;

proc print data=one(obs=50);
 title 'First few observations of the original data';
run;

proc gplot data=one;
 title 'original series';
 plot y*x;
run;

proc expand data=one out=three method=spline ;
 convert y=total/observed=(beginning,total) transformout=(sum);
 id x;
run;

Handling the look up table using proc SQL

/*******************************************************************/
/*   The program below is to select the observations with          */
/*   questionable STLFRQ1N                                         */
/*******************************************************************/

proc sql;
  ***Create a look up table;
  create table abnormal as
  select distinct stysid1a,stlfrq1n
  from dm.asm_2
  where stlfrq1n >=11;

  ***Select records based on the look up table;
  create table abnormal2 as
  select stysid1a, asm1d, stlfrq1n
  from dm.asm_2
  where stysid1a in (select stysid1a from abnormal) and stlfrq1n ne . ;
quit;