The SURVEYMEANS procedure might produce incorrect domain quantiles when there is an empty domain


When the following conditions are met in PROC SURVEYMEANS:

the quantiles and standard errors are incorrect from the empty domain through the last row in the Domain Quantiles table. An output data set generated from the DomainQuantiles ODS table is similarly affected.

Quantiles are requested when any of the following options are specified in the PROC SURVEYMEANS statement:

You can detect an empty domain by specifying the NOBS option in the PROC SURVEYMEANS statement and checking the Domain Statistics table. A value of N=0 indicates an empty domain.

To circumvent the problem, create a new domain variable using a custom format that places the empty domain in the last sorted order. The following program demonstrates the use of a custom format to generate correct domain quantiles when there is an empty domain.

*The following DATA step generates a test data set A with four levels of Education and random values of Y. One of the Education levels, 'College Grad', is empty because it is assigned a missing value of Y for every one of its observations.;

data a;
   length Education $ 15;
   do Education='High School', 'Some College', 'College Grad', 'Advanced Degree';
      do i=1 to 25;
         y=rannor(12345);
         if Education='College Grad' then y=.;
         output;
      end;
   end;
   run;

*The number of observations, mean and median of Y are requested for the overall data set and the domain levels;
title "N=0 for a domain level";
title2 "The quantile results are incorrect starting from the empty domain";
proc surveymeans data=a nobs mean median;
   var y;
   domain Education;
   run;
title;

*Notice in the output that N=0 for College Grad, indicating an empty domain;
*The quantile results in the Domain Quantiles table are incorrect for the College Grad level and all subsequent Education levels.;

*The following PROC FORMAT step creates a custom format, REORDER, which places College Grad last if you sort on the formatted values;

proc format;
   value $ reorder
      'High School'='(1) High School'
      'Some College'='(2) Some College'
      'Advanced Degree'='(3) Advanced Degree'
      'College Grad'='(4) College Grad';
   run;

*Create a new domain variable by applying the REORDER format;

data a;
   set a;
   Education2=put(Education, $reorder.);
   run;

*Use the new domain variable in PROC SURVEYMEANS, and all of the domain quantile results are now correct;
title "Placing the empty domain last fixes the domain quantile results";
proc surveymeans data=a nobs mean median;
   var y;
   domain Education2;
   run;
title;