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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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