BookmarkSubscribeRSS Feed
takahasm
Calcite | Level 5

Hello,

 

I want to know the top 3 most common reason for visit for each birth group for a dataset with 2 columns where:

  • Column 1 has birth group (so like child, senior, adult, etc) [BD_CLASS] 
  • Column 2 has that’s their reason for visiting the ER. [main_problem]

 

I tried using 

PROC SQL;
SELECT BD_CLASS, count(unique(main_problem)) as u_PROB
FROM work.test12
group by BD_Class;
quit;

but that only told me the number of unique problems in each birth group; not the most popular ones. 

 

Any help would be much appreciated

 

 

3 REPLIES 3
ballardw
Super User

Does this have to be done with SQL?

takahasm
Calcite | Level 5

no it doesn't! 

Reeza
Super User
1. Try ordering the data, so sort by U_PROB descending so that the top are on top.
2. Add OUTOBS=3 to limit to the top 3 but then you may lose any duplicates.

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
  • 3 replies
  • 564 views
  • 0 likes
  • 3 in conversation