SUPPORT / SAMPLES & SAS NOTES
 

Support

Usage Note 34607: How can I compare means in PROC SURVEYMEANS?

DetailsAboutRate It

Beginning in SAS/STAT 14.2 in SAS 9.4 TS1M4, you can use the DIFF option in the DOMAIN statement to compare the means of continuous variables. Refer to the SAS OnlineDoc® documentation for details and additional options.

In earlier releases, you can use PROC SURVEYREG to compare means instead.

Example

The following DATA step creates a data set named SAMPLE, representing a stratified and clustered sample design. Measurements are obtained on three variables, X1, X2 and X3, and there is a domain variable D with two levels.

data sample;
  w=1;
  seed=273497;
  do str=1 to 2;
    do clus=1 to 3;
      do i=1 to 5;
        d=ceil(2*ranuni(seed));
        X1=rannor(seed);
        X2=rannor(seed);
        X3=rannor(seed);
        output;
      end;
    end;
  end;
  drop seed i;
run;
proc print data=sample(obs=10);
run;

Here is the partial printout of the data set:

Data

 

PROC SURVEYMEANS can compute the overall and domain means and their standard errors as follows.

proc surveymeans data=sample;
  domain d;
  cluster clus;
  strata str;
  weight w;
  var X1 X2 X3;
run;

Statistics

Domain

 

 

In order to use PROC SURVEYREG for variable means comparisons, first reshape the data so that it is arranged for an ANOVA. That is, so that all the measurements are in a single variable and there is a class indicator variable. This DATA step creates the analysis variable MEASUREMENT containing the X1, X2 and X3 values and the class variable GROUP.

data sample2;
  set sample;
  array num (*) x1 x2 x3;
  length group $ 8;
  do i=1 to dim(num);
    measurement=num[i];
     call vname(num[i], group);
     output;
   end;
drop x1 x2 x3 i;
run;
proc print data=sample2(obs=10);
run;

Here is the partial printout of the reshaped data.

Reshaped Data

 

To set up an equivalent analysis in PROC SURVEYREG, specify the same design and weight statements that you had in PROC SURVEYMEANS. The model response variable is MEASUREMENT, the set of all analysis variable values from the reshaped data, and the independent class variable is GROUP, the ID variable also created in the reshaped data. It is convenient to specify a no-intercept model with the NOINT option, so that the parameter estimates are equal to the analysis variable means. The following CONTRAST statement in PROC SURVEYREG compares the means of X1, X2 and X3.

proc surveyreg data=sample2;
   cluster clus;
   strata str;
   weight w;
   class group;
   model measurement=group/noint solution vadjust=none;
   contrast 'Ho: X1=X2=X3' group 1 -1 0, group 1 0 -1;
run;

Header

Coeffs

 

Note that the VADJUST= option is specified. VADJUST=DF by default in PROC SURVEYREG, which uses the degrees of freedom adjustment factor (n-1)/(n-p) in the G matrix. This results in different variance estimates in PROC SURVEYREG than those obtained in PROC SURVEYMEANS. By using VADJUST=NONE, the same variance estimates can be obtained in PROC SURVEYREG. The VADJUST= option was added in SAS 9.1. Prior to SAS 9.1, you would have to use the %SMSUB macro to compute contrasts for variables or domain levels.

You can compare the domain means using the original data set. This code compares the mean of X1 between the two domains.

ods select parameterestimates contrasts;
proc surveyreg data=sample;
  cluster clus;
  strata str;
  weight w;
  class d;
  model X1=d/noint solution vadjust=none;
  contrast 'X1: D1 vs D2' d 1 -1;
run;

Header

Coeffs

 

Additional help on writing contrasts is presented in Examples of Writing CONTRAST and ESTIMATE Statements.



Operating System and Release Information

Product FamilyProductSystemSAS Release
ReportedFixed*
SAS SystemSAS/STAT64-bit Enabled Solaris
64-bit Enabled HP-UX
64-bit Enabled AIX
Windows Millennium Edition (Me)
Windows Vista
Microsoft Windows XP Professional
Microsoft Windows Server 2003 Standard Edition
Microsoft Windows Server 2003 Enterprise Edition
Microsoft Windows Server 2003 Datacenter Edition
Microsoft Windows NT Workstation
Microsoft Windows 2000 Professional
Microsoft Windows 2000 Server
Microsoft Windows 2000 Datacenter Server
Microsoft Windows 2000 Advanced Server
OS/2
Microsoft Windows 95/98
Microsoft® Windows® for x64
Microsoft Windows XP 64-bit Edition
Microsoft Windows Server 2003 Enterprise 64-bit Edition
Microsoft Windows Server 2003 Datacenter 64-bit Edition
Microsoft® Windows® for 64-Bit Itanium-based Systems
OpenVMS VAX
z/OS
ABI+ for Intel Architecture
AIX
HP-UX
HP-UX IPF
IRIX
Linux
Linux for x64
Linux on Itanium
OpenVMS Alpha
OpenVMS on HP Integrity
Solaris
Solaris for x64
Tru64 UNIX
* For software releases that are not yet generally available, the Fixed Release is the software release in which the problem is planned to be fixed.