Hi all,
I am struggling with making weighted averages shown.
I have 3 parameters - EAD (a number), LGD (a number) and PD (a series of percentages). These are in a sas-dataset of which the output has been verified and is known to be correct.
Needed is, for each of the 3, their averages produced but not normal averages; but weighted avg ; weighted by exposure total (EAD-total).
It takes a grouping sum to sort it out.
Can anyone explain to me how this works?
I found out how to do; made 1 example calculation using proc means + keyword weight.
But stakeholders requested to see it done manually by use of the querybuilders which are graphically available in SAS EnterpriseGuide rather than by code.
And I have been staring at the problem for a while but I cannot seem to get it done with graphic user-interface SAS E.G. querybuilders, so. Does anyone have a code and example data for me? I'm on SAS E.G. v8.
Thanks & best regards,
Heleen
See an example how you work with weighted averages:
data have;
input group value;
datalines;
1 3
1 5
2 6
2 8
2 10
;
proc sql;
create table weighted as
select group, mean(value) as value, count(*) as weight
from have
group by group
;
select mean(value) as want1
from have;
select sum(value*weight) / sum(weight) as want2
from weighted;
quit;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.