BookmarkSubscribeRSS Feed
Mattress58
Fluorite | Level 6

I created a table named rentals. This is what it pulls back.

ScoreXWeightX

1

10
023
045
420
220
15
15

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?

4 REPLIES 4
PaigeMiller
Diamond | Level 26

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;

--
Paige Miller
Reeza
Super User

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;

PaigeMiller
Diamond | Level 26

I think you want

select sum((scorex ne 0)*weightx)/sum((scorex=1)*weightx) as score

--
Paige Miller
Mattress58
Fluorite | Level 6

Thank you both for the help.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1776 views
  • 1 like
  • 3 in conversation