I created a table named rentals. This is what it pulls back.
ScoreX | WeightX |
---|---|
1 | 10 |
0 | 23 |
0 | 45 |
4 | 20 |
2 | 20 |
1 | 5 |
1 | 5 |
I need to come up with the result being
Score |
---|
3 |
Which is a formula of (sum All weightX wher scoreX not = to 0) / (sum All weightx where score = to 1)
so
60/20
How can I do this?
data oink;
set rentals end=eof;
if scoreX^=0 then numerator+weightx;
if scoreX=1 then denominator+weightx;
if eof then score=numerator/denominator;
run;
It's 68/20=3.4 given your data.
Here's a SQL solution...
proc sql;
create table want as
select sum((scorex=0)*weightx)/sum((scorex=1)*weightx) as score
from have;
quit;
I think you want
select sum((scorex ne 0)*weightx)/sum((scorex=1)*weightx) as score
Thank you both for the help.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.