BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SASuser4321
Obsidian | Level 7

I have two columns in a table. 

I need to find the number of rows in which the number in Rating_a is bigger than the number in Rating_b and then divide that number by the total number of rows in the table in which the value changes. So when dividing, I won't be taking into account those rows in which the values in Rating_a and Rating_b are the same. For instance, in the following table, the result I'd be looking for is 2/4 = 50%. I divide by 4 instead of 6 because 2 rows have the same values. And in the numerator I wrote 2 because only in 2 rows, rating_a is bigger than rating_b. Help would be appreciated in coming up with a code that deals with this since I'm dealing with 1000s of rows in my table. Thank you.

Here's a sample (actual table has 1000s of rows) of how it looks like:

Rating_a Rating_b
1 3
2 2
4 2
4 4
2 1
3 4

 

1 ACCEPTED SOLUTION

Accepted Solutions
SASuser4321
Obsidian | Level 7

I figured it out on my own. 🙂

proc sql;
select sum(rating_a > rating_b) / sum(rating_a ne rating_b) from have;
quit;

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Since you marked an answer correct to your other question, can you see if you can make the simple modifications to that answer? Show us what you have tried.

--
Paige Miller
SASuser4321
Obsidian | Level 7

I figured it out on my own. 🙂

proc sql;
select sum(rating_a > rating_b) / sum(rating_a ne rating_b) from have;
quit;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2 replies
  • 389 views
  • 0 likes
  • 2 in conversation