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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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