Date: Fri, 6 Oct 2006 10:22:45 -0400 Jim Groeneveld "SAS(r) Discussion" Jim Groeneveld Re: Weighted Average To: Aknas Dii

Right Dii,

David C. gave you a solution to vertically determine a weighted average, i.e. across rows (observations or records). I'll give you a solution to horizontally determine a weighted average, i.e. across columns (variables within observations). I could use David's solution with a PROC TRANSPOSE on either side, but that would make it unnecessarily complicated. I'll do it directly in a data step, manipulating variables, just like you do it in Excel. I'm not entirely familiar with Excel, so I don't know the exact syntax of the SUMPRODUCT function, but I assume C is the weight of A and D of B. Is that correct? Furthermore in SAS the percent sign is not included in the numeric values of A, B and the weighted average. It can be added via a format.

* Weighted average within each record; WgtAve = ( A*C + B*D ) / ( C+D );

And as the result probably will have many decimals you should format it with a numeric SAS format, e.g. to only show the integer (rounded) values.

Regards - Jim. -- Jim Groeneveld, Netherlands Statistician, SAS consultant home.hccnet.nl/jim.groeneveld

My computer remains home while I will attend PhUSE 2006 in Dublin. Traveling to Dublin on 7 October, congress from 9 to 11 October. See: www.phuse.info

On Thu, 5 Oct 2006 10:35:06 -0400, Aknas Dii <aknas_a@YAHOO.COM> wrote:

>Here is excel formula to produce this result : >=SUMPRODUCT(A2:B2,C2:D2)/SUM(C2:D2) > >A B C D weighted average >14% 0% 72 368 2% >54% 0% 72 368 9% >4% 2% 72 368 2% >1% 0% 72 368 0% >26% 0% 72 368 4% >0% 1% 72 368 1% >3% 1% 72 368 1% > >Would like to get SAS code to produce the weighted average. > >Thanks > >Dii.

Back to: Top of message | Previous page | Main SAS-L page