如何将子组与SAS中的整个组进行比较?

How to compare the subgroup with the entire group in SAS?

我正在使用 SAS 9.4 执行我的分析。因为我的数据来自复杂的调查,所以需要用PROC SURVEYMEANS/SURVEYFREQ/SURVEYREG等来占权重。我的原始数据集有大约 1000 个观察值。

我有一个子组 (n=300),我使用 sel=1 作为变量来表示这个组。现在我想比较子组(n=300)和原始组(n=1000)之间的一些特征。我想知道该怎么做。我试过这个:

proc surveyfreq data=mydata;
stratum str;
cluster clu;
weight wt;
table sel*(c1 c2 c3 c4)/chisq;
run;

proc surveymeans data=mydata nomcar nobs mean stderr ;
stratum str;
cluster clu;
weight wt;
var c5 c6;
domain sel/diffmeans;
run;

但是,这样一来,我只能得到选中组(n=300)和未选中组(n=700)之间的比较。我想知道如何将所选组 (n=300) 与整个组 (n=1000) 进行比较。

谢谢!

您可以将数据与自身堆叠起来,并以此为基础创建一个新的分类变量。

此调整可能导致surveymeans由于重复而错误地执行某些计算。

data tweak;
  * stack selected obs with all obs;
  set 
    have(where=(sel=1) in=one)
    have(in=all)
  ;

  * new category;
  if one then 
    selcat = 'Only Sel';
  else
    selcat = 'All';
run;

proc surveymeans data=tweak nomcar nobs mean stderr ;
  stratum str;
  cluster clu;
  weight wt;
  var c5 c6;
  domain selcat / diffmeans ;
run;