I have two columns in a table.
I need to find the number of rows in which Rating_a is not equal to Rating_b and then divide that number by the total number of rows in the table. Basically, I need to find the percentage of where the values differ. Could someone please help me with this? I think using the COUNT function could work. Help would be appreciated. Thank you.
Here's a sample (actual table has 1000s of rows) of how it looks like:
| Rating_a | Rating_b |
| 1 | 1 |
| 2 | 3 |
| 4 | 4 |
| 4 | 1 |
| 3 |
3 |
proc sql;
select sum(rating_a = rating_b) / count(*) as percentage format=percent7.2 from have;
quit;
proc sql;
select sum(rating_a = rating_b) / count(*) as percentage format=percent7.2 from have;
quit;
Would there ever be missing values? How would those be handled?
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.