Help using Base SAS procedures

Sum up with

Reply
Occasional Contributor
Posts: 7

Sum up with

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?

Trusted Advisor
Posts: 1,613

Re: Sum up with

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;

Super User
Posts: 17,819

Re: Sum up with

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;

Trusted Advisor
Posts: 1,613

Re: Sum up with

I think you want

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

Occasional Contributor
Posts: 7

Re: Sum up with

Thank you both for the help.

Ask a Question
Discussion stats
  • 4 replies
  • 360 views
  • 1 like
  • 3 in conversation