BookmarkSubscribeRSS Feed
elopomorph
Calcite | Level 5

I created SAS code using proc SQL to calculate a weighted mean by year.  My SAS code is below.  My weight variable is called bwght and I weight the variable called CPUE for each year.  This code produces the weighted mean by year and calls it bwghtedAverage.  However, I can't figure out how I an get proc sql to also provide me with the 95% confidence intervals for this mean.  Any help would be greatly appreciated.   

proc sql;

   title 'Weighted Averages';

   select Year, sum(CPUE*bwght)/sum(bwght) as bwghtedAverage

       from (select Year, CPUE,

                   case

                      when bwght gt 0 then bwght

                      else 0

                   end as bwght

               from CPUEdat)

      group by Year /*major_area_code*/;

quit;

4 REPLIES 4
Reeza
Super User

You'd have to do the manual calculations using the formula. Why not use proc means instead?

elopomorph
Calcite | Level 5

I don't know how to do a weighted average in proc means.  Can you provide an example? 

Reeza
Super User

Here's a good example of how and looking at the vardef option as well. 

Base SAS(R) 9.2 Procedures Guide

You'll still need to deal with the 0 or negative weights somehow before the proc.

Ksharp
Super User

And don't forget   proc univariate

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 3832 views
  • 0 likes
  • 3 in conversation