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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.