BookmarkSubscribeRSS Feed
fdb00004
Fluorite | Level 6

Hello Guys,

I would like to sort my table based on frequency od values. This is my table and code

Data df;
    Input Players $  Clubs 9-25$;
    datalines;
Ronaldo     ManUnited
Ronaldo     ManUnited
Ronaldo     RealMadrid
Suarez      Liverpool
Suarez Liverpool ; run; proc freq data=df; table Players*Clubs / out=counts; run; proc sort data=counts; by players descending Count; run;

I have tried this code but no result. Below is my desired output.

Players     Clubs
Ronaldo     ManUnited
Suarez      Liverpool

Thanks.

4 REPLIES 4
Reeza
Super User
The RealMadrid line disappears? What is the logic to remove that line?
fdb00004
Fluorite | Level 6

 My mistake. I have edited the code. RealMadrid should not appear but I only want rows with 2 or more frequent outcome like Liverpool to appear on the table.

Reeza
Super User
You can add data set options to any data set.
This adds a where filter to your summary so only records with 2 or more counts are displayed.

proc freq data=df;
table Players*Clubs / out=counts (where = (counts >=2));
run;
ballardw
Super User

The code you show will not generate the output. Your data step will create the Clubs with only 8 characters, so the result will be "ManUnite".

And correcting that the result will have 3 records.

Players      Clubs       COUNT    PERCENT

Ronaldo    ManUnited       2         50
Ronaldo    RealMadrid      1         25
Suarez     Liverpool       1         25

So you have likely done more than you are showing in the code.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 4 replies
  • 951 views
  • 1 like
  • 3 in conversation