Two-Sample Quantile Test SAS Macro for Right Censored Survival Data

https://mkosorok.web.unc.edu/wp-admin/edit.php?post_type=pageThe general algorithm used for two-sample quantile testing for right censored survival data is described in detail in the paper “Two-sample quantile tests under general conditions” by Michael R. Kosorok, which appeared in Biometrika (1999) and can be downloaded by clicking here. We now discuss a simple SAS implementation of the special setting for two independent right censored survival samples. The SAS macro was written by Minjung Kwak under guidence from Michael R. Kosorok. The project was initiated at the request of Mike Mosier and fully funded by EMB Statistical Solutions, LLC. The null hypothesis tested is that the quantiles, with quantile probability p, are equal but that other aspects of the distributions may differ between the two samples. We recommend reading the paper thoroughly before using the macro described below.

To incorporate the software into SAS, insert the code obtained by clicking here into SAS. To do this in a unix environment, copy and paste this code in a SAS program window and then submit it. This procedure will define the macro. Or you can simply add this code into your SAS program ahead of any place where you actually wish to use the macro.


The macro qtest.sas will calculate the two-sample quantile statistics and the p-value for the two-sample test. The distribution for sample 1 is denoted F, while the distribution for sample 2 is denoted G.

The Input Parameters are:

  • DATA1 (Required) = Random sample from F. It consists of two columns. First column contains the time to event. Second column contains censoring value( 1 = event, 0 = censoring ).
  • DATA2 (Required) = Random sample from G. It consists of two columns. First column contains the time to event. Second column contains censoring value( 1 = event, 0 = censoring ).
  • TIME1 (Required) = Variable containing time to event or last follow-up in any units in DATA1.
  • TIME2 (Required) = Variable containing time to event or last follow-up in any units in DATA2.
  • P (Required) = The probability of which the quantile would be tested. The null hypothesis is that the pth quantile of the F distribution is same as the pth quantile of the G distribution. .
  • Q (Default is 0.25) = Bandwidth adjustment term for kernel density estimation.
  • ALPHA (Default is 0.05) = Type I error.
  • OUT (Default name is _QTEST) = Data set name where the output would be stored.
  • PRINTOP(Default is 1) = Option for printing output. 1 = YES, 0 = NO.

Output Dataset _QTEST includes the following variables:

  • NUM_F = The number of observations in DATA1.
  • NUM_G = The number of observations in DATA2.
  • XI_F = Estimate of pth quantile of distribution F.
  • XI_G = Estimate of pth quantile of distribution G.
  • DIFF = Estimate of difference between the two quantiles, i.e., F_inv(p)-G_inv(p).
  • STD_ERR = Standard error estimate for the quantile difference.
  • LOWER = Lower bound of 100(1-ALPHA)% confidence interval for quantile difference.
  • UPPER = Upper bound of 100(1-ALPHA)% confidence interval for quantile difference.
  • CHISQ = Observed chi-square statistics for testing the equality of two quantiles.
  • PVALUE = p-value (probability of a greater chi-square value)

Example :

%SurvQtest(data1=mydat1,data2=mydat2,time1=x,time2=x,p=0.5);

Funding for this software was provided by EMB Statistical Solutions, LLC. The software was written by Minjung Kwak under advice from Michael R. Kosorok in March, 2005.