## Top 10 list

Solved
Frequent Contributor
Posts: 79

# Top 10 list

Dear all,

My data set has 1 char and 1 Num var, the char var has duplicates but the numeriv value for the particular char value will be unque as in given example, I am currently struggling to get the Top 10 count in  num(sorted order ) as shown below pls help!!

Have dataset

name      score

-------      --------

John       2500

john        2000

mell         5000

shawm    4850

Mell         9000

Mike        2500

Mike        1650

Mike        6570

ness        2330

Want data set - Top 3 names

Name

 Mell 14000 Mike 10720 Shawn 4850

Accepted Solutions
Solution
‎11-08-2017 03:07 AM
Frequent Contributor
Posts: 116

## Re: Top 10 list

[ Edited ]

Try this....

``````proc sql;
create table WANT as
select
upcase(name) as name,
sum(score) as total_score
from HAVE
group by calculated name order by calculated SCORE desc;
quit;data WANT;  set WANT(obs=10);run;``````

Hope this helps...

All Replies
Occasional Contributor
Posts: 9

## Re: Top 10 list

Hi,

Something like the following will get you the score totals for each name:

``````proc sql;
create table want as
select distinct name, sum(score) as total
from have
group by name
order by total desc ;
quit;``````

You should then be able to write a step to keep only the top 3.

Good luck,

Lee

Valued Guide
Posts: 595

## Re: Top 10 list

Proc Rank could do it in one step e.g.

``````proc rank data=sashelp.class out=want(where=(rank<=3)) descending;
var weight;
ranks rank;
run;``````
Solution
‎11-08-2017 03:07 AM
Frequent Contributor
Posts: 116

## Re: Top 10 list

[ Edited ]

Try this....

``````proc sql;
create table WANT as
select
upcase(name) as name,
sum(score) as total_score
from HAVE
group by calculated name order by calculated SCORE desc;
quit;data WANT;  set WANT(obs=10);run;``````

Hope this helps...

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
• 3 replies
• 305 views
• 1 like
• 4 in conversation