I am using SAS 9.4 to perform my analysis. Because my data comes from a complex survey, I need to use PROC SURVEYMEANS/SURVEYFREQ/SURVEYREG
, etc. to account for the weight. My original dataset has about 1000 observations.
I have a subgroup(n=300) and I use sel=1
as a variable to indicate this group. Now I would like to compare some features between the subgroup(n=300) and the original group(n=1000). I was wondering how to do that. I tried this:
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;
However, in this way, I can only get the comparison between the selected group(n=300) and the unselected group(n=700). I was wondering how I can compare the selected group(n=300) with the entire group(n=1000).
Thank you!
You can stack the data with itself and create a new categorical variable based on that.
This tweak might cause surveymeans
to perform some computations incorrectly due to the repetitions.
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;