When I run proc means, the standard deviations are very high.
The variables in the statement below are all binary, so the std should be sqrt(p*(1-p)), as shown in the table below. Instead they are orders of magnitude bigger. I get the same problem with continuous variables; stata delivers much smaller std errors.
No-one else seems to have this problem, and Ive been having it for years, so it has to be something I have misunderstood about proc means.I t might have something to do with the weight statement. The weights post_wt range in size from 350 to 33500.
Please let me know how to get the correct std dev. I'm getting tired of porting my sas data sets to stata.
THanks
J
Variable | N | Mean | Std Dev | Minimum | Maximum | sqrt(p(1-p)) |
PregMonth | 296527 | 0.006651 | 5.973354 | 0 | 1 | 0.081281 |
PregBirth | 296527 | 0.003967 | 4.619279 | 0 | 1 | 0.062856 |
MarrMonth | 296527 | 0.006756 | 6.020052 | 0 | 1 | 0.081917 |
ShotGunMar | 296527 | 0.00106 | 2.391512 | 0 | 1 | 0.032542 |
20462 proc means data=sinwom; *noprint;;
20463 var PregMonth PregBirth MarrMonth ShotGunMar;
20464 *output out=temp mean = PregMonth PregBirth MarrMonth ShotGunMar;
20465 weight post_wt;
20466 *proc print;
20467 run;
NOTE: There were 296527 observations read from the data set WORK.SINWOM.
NOTE: PROCEDURE MEANS used (Total process time):
real time 0.19 seconds
cpu time 0.29 seconds
proc means data=sinwom vardef=wdf ;
var PregMonth PregBirth MarrMonth ShotGunMar;
weight post_wt;
run;
-------------------
Edit: I am sorry that my code is wrong, because i missed your below comment.
>The variables in the statement below are all binary,
proc means data=sinwom vardef=wdf ;
var PregMonth PregBirth MarrMonth ShotGunMar;
weight post_wt;
run;
-------------------
Edit: I am sorry that my code is wrong, because i missed your below comment.
>The variables in the statement below are all binary,
This solved the problem. std dev now exactly as predicted in my post. also vardef=weight gave the same result. Many thanks!
Thanks for the suggestion. It looks like the problem was not the dataset but my incomplete understanding of the weight statement.
Formula is sqrt(n*p*(1-p)) isn't it?
Have you tried using PROC SURVEYMEANS if you have weighed data, from surveys in particular, it may be more appropriate.
There's also a note in PROC MEANS weight statement:
@john_knowles wrote:
When I run proc means, the standard deviations are very high.
The variables in the statement below are all binary, so the std should be sqrt(p*(1-p)), as shown in the table below. Instead they are orders of magnitude bigger. I get the same problem with continuous variables; stata delivers much smaller std errors.
No-one else seems to have this problem, and Ive been having it for years, so it has to be something I have misunderstood about proc means.I t might have something to do with the weight statement. The weights post_wt range in size from 350 to 33500.
Please let me know how to get the correct std dev. I'm getting tired of porting my sas data sets to stata.
THanks
J
Variable N Mean Std Dev Minimum Maximum sqrt(p(1-p)) PregMonth 296527 0.006651 5.973354 0 1 0.081281 PregBirth 296527 0.003967 4.619279 0 1 0.062856 MarrMonth 296527 0.006756 6.020052 0 1 0.081917 ShotGunMar 296527 0.00106 2.391512 0 1 0.032542 20462 proc means data=sinwom; *noprint;;
20463 var PregMonth PregBirth MarrMonth ShotGunMar;
20464 *output out=temp mean = PregMonth PregBirth MarrMonth ShotGunMar;
20465 weight post_wt;
20466 *proc print;
20467 run;
NOTE: There were 296527 observations read from the data set WORK.SINWOM.
NOTE: PROCEDURE MEANS used (Total process time):
real time 0.19 seconds
cpu time 0.29 seconds
Be aware that weights are not frequencies. If these numbers represent the number of cases, you should use the FREQ statement instead of the WEIGHT statement.
If you really have weights, then the SAS documentation provides the formulas for weighted statistics. Compare those formulas against the formulas for the other software. My guess is that it is a divisor issue. SAS provides four possible divisors for a weighted statistic such as the StdDev. By default, the divisor is (n-1), which is the usual unweighted divisor. Try using VARDEF=WEIGHT on the PROC MEANS statement to use the sum of weights as the divisor.
You are right. Using FREQ instead of WEIGHT gave the correct results. I wonder if back in SAS 5 when I first learned SAS, this distinction was not critical....
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.