I am creating a bunch of frequency tables using proc tabulate
, and I have to weigh the percentage according to a set of weights regarding the age of each person
in my dataset. My problem is that it seems like the weights have any impact on my results. I know, I can do this with proc freq, but my tables are pretty detailed, and therefore I am using proc tabulate.
I have included an example of a dataset, and what I have tried so far:
Data have;
input gender wgt q1 year;
lines;
0 1.5 0 2014
0 1 1 2014
0 1.5 1 2014
0 1 1 2014
0 1.5 0 2014
1 1 1 2014
1 1 1 2014
1 1 1 2014
1 1 0 2014
1 1 1 2014
1 1 1 2014
;
run;
Proc format;
value gender 0="boy";
1= "girl";
value q1f 0= "No"
1="Yes";
run;
Proc tabulate data=have;
class gender q1 year;
weight wgt;
table gender*pctn<q1>, year*q1;
format gender gender. q1 q1f.;
run;
I know the results should be that app. 46,2 %
boys have answered "No" and app. 53,8 % have answered yes, when I include the weights, but the output from the proc tabulate gives me 40 % No and 60 % yes among the boys.
What have I done wrong?
sas
language, but without weights, the output is correct because 3/5 boys voted yes (60%). So maybe you need need to do something liketable gender*pctn<q1*wgt>, year*q1
- rhavelkaproc freq data = have; table gender * q1 /nocol nopercent nofreq; weight wgt; format gender gender. q1 q1f.; run;
- user667489