BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
john_knowles
Calcite | Level 5

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
amatsu
Obsidian | Level 7
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

6 REPLIES 6
amatsu
Obsidian | Level 7
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,

john_knowles
Calcite | Level 5

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

john_knowles
Calcite | Level 5

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

Reeza
Super User

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

 

 


 

 

 

 

Rick_SAS
SAS Super FREQ

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. 

 

 

john_knowles
Calcite | Level 5

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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