BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
don21
Quartz | Level 8

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

 

Please help!!

1 ACCEPTED SOLUTION

Accepted Solutions
ShiroAmada
Lapis Lazuli | Level 10

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...

View solution in original post

3 REPLIES 3
BenbowL
Fluorite | Level 6

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

ChrisBrooks
Ammonite | Level 13

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;
ShiroAmada
Lapis Lazuli | Level 10

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...

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 10204 views
  • 2 likes
  • 4 in conversation