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 |
I figured it out on my own. 🙂
proc sql;
select sum(rating_a > rating_b) / sum(rating_a ne rating_b) from have;
quit;
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.
I figured it out on my own. 🙂
proc sql;
select sum(rating_a > rating_b) / sum(rating_a ne rating_b) from have;
quit;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.