Sample Code for the _boot macro

Date: March 2003
/** 
This program is used to test the _boot macro.  This macro will 
calculate confidence intervals around a median.  

The open code below calculates the confidence interval for a median
using method suggested by KC.
**/

**** Include the macro.
%include '_boot.sas' ;

**** Define library to find data ;
libname aac '/project/aac99/data' ;

**** Set the sample data ;
data testboot ;
    set aac.sample1 ;
    format _all_ ;
    run;
    
**** Run bootstrap macro ;
_boot data=testboot repeat=500 var=los ci=95 ;

*** Compare with KC Method ;
  *** Calculate median and number of observations ;
  proc univariate data=testboot  noprint ;
        var los ;
        output out=itest  median=median n=n  ;
        run ;
  
  *** Determine observation for lower and upper confidence interval ;
  data itest ;
     set itest ;
     z = probit(0.05/2) ;  *** set alpha here, divide by 2 for two tailed test ;
     upper = ceil(((n+1)/2)+((n)**0.5)/2*z) ; 
     lower = floor(((n+1)/2)-((n)**0.5)/2*z) ;
     run;
  
  *** Sort by LOS to oder the dataset (rank order) by los ;
  proc sort data=testboot ;
     by los ;
     run;
  
  *** Identify upper and lower observation and and get associated value ;
  data test ;
     if _n_ = 1 then set itest ;
     set testboot ;
     if _n_ = lower then do ; ci='Lower' ; output ; end ;
     if _n_ = upper then do ; ci='Upper' ; output ; end  ;
     run;
  
  proc print data=test ;
     var ci los median ;
     run;

©2003 Manitoba Centre for Health Policy (MCHP)