Help using Base SAS procedures

proc means standard deviation too high? SAS 9.4

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

proc means standard deviation too high? SAS 9.4

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

 

 

VariableNMeanStd DevMinimumMaximumsqrt(p(1-p))
PregMonth2965270.0066515.973354010.081281
PregBirth2965270.0039674.619279010.062856
MarrMonth2965270.0067566.020052010.081917
ShotGunMar2965270.001062.391512010.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

 

 


Accepted Solutions
Solution
‎06-15-2018 10:38 AM
Occasional Contributor
Posts: 6

Re: proc means standard deviation too high? SAS 9.4

[ Edited ]
Posted in reply to john_knowles
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,

View solution in original post


All Replies
Solution
‎06-15-2018 10:38 AM
Occasional Contributor
Posts: 6

Re: proc means standard deviation too high? SAS 9.4

[ Edited ]
Posted in reply to john_knowles
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,

New Contributor
Posts: 4

Re: proc means standard deviation too high? SAS 9.4

This solved the problem. std dev now exactly as predicted in my post. also vardef=weight gave the same result. Many thanks!

New Contributor
Posts: 4

Re: proc means standard deviation too high? SAS 9.4

Posted in reply to john_knowles

Thanks for the suggestion. It looks like the problem was not the dataset but my incomplete understanding of the weight statement.  

Super User
Posts: 23,689

Re: proc means standard deviation too high? SAS 9.4

[ Edited ]
Posted in reply to john_knowles

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:

 

CAUTION:
Single extreme weight values can cause inaccurate results.
When one (and only one) weight value is many orders of magnitude larger than the other weight values (for example, 49 weight values of 1 and one weight value of 1×1014), certain statistics might not be within acceptable accuracy limits. The affected statistics are based on the second moment (such as standard deviation, corrected sum of squares, variance, and standard error of the mean). Under certain circumstances, no warning is written to the SAS log.
 
 
The detailed section on weights has more information that may help you narrow down the issue. 
 
Can you replicate these results on someone else's machine? Or provide a sample that reflects this issue. You don't have to provide any individual information, just the 1/0 and the respective weight so we can replicate the issue and debug if necessary.
 
Edit: From @amatsu users answer, the weight pages has examples. In their case, the weights increase the StDev though. 
 

@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

 

 


 

 

 

 

SAS Super FREQ
Posts: 4,240

Re: proc means standard deviation too high? SAS 9.4

Posted in reply to john_knowles

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. 

 

 

New Contributor
Posts: 4

Re: proc means standard deviation too high? SAS 9.4

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....

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 279 views
  • 2 likes
  • 4 in conversation