BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sasphd
Lapis Lazuli | Level 10

Hello I want to select the rows having the maximum value of total score by secid. 

 

I do this but do not works 

proc sql;
create table max as
select distinct *
from CRSP_data3
having TOTAL_SCORE=max(TOTAL_SCORE)
order by secid;
run;

 

secid Fund_name Inception_date CRSP_FUNDNO FUND_NAME_CRSP TOTAL_SCORE
F000002KYY JHancock Disciplined Value R4 2009-05-22 46807 John Hancock Funds III: John Hancock Disciplined Value Fund; Class R3 Shares 50
F000002KYY JHancock Disciplined Value R4 2009-05-22 46808 John Hancock Funds III: John Hancock Disciplined Value Fund; Class R4 Shares 75
F000002KYY JHancock Disciplined Value R4 2009-05-22 46809 John Hancock Funds III: John Hancock Disciplined Value Fund; Class R5 Shares 50
F000002KYY JHancock Disciplined Value R4 2009-05-22 46811 John Hancock Funds III: International Core Fund; Class R4 Shares 25
F000002KYY JHancock Disciplined Value R4 2009-05-22 46815 John Hancock Investment Trust: John Hancock Fundamental Large Cap Core Fund; Class R4 Shares 25
F000002KYY JHancock Disciplined Value R4 2009-05-22 46815 John Hancock Investment Trust: John Hancock Large Cap Equity Fund; Class R4 Shares 25
F000002KYY JHancock Disciplined Value R4 2009-05-22 46821 John Hancock Funds III: US Core Fund; Class R4 Shares 25
F000002KYY JHancock Disciplined Value R4 2009-05-22 46823 John Hancock Capital Series: John Hancock Classic Value Fund; Class R3 Shares 25
F000002KYY JHancock Disciplined Value R4 2009-05-22 46824 John Hancock Capital Series: John Hancock Classic Value Fund; Class R4 Shares 50
F000002KYY JHancock Disciplined Value R4 2009-05-22 46825 John Hancock Capital Series: John Hancock Classic Value Fund; Class R5 Shares 25
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

You are missing GROUP BY

 

So-

proc sql;
create table max as
select  *
from CRSP_data3
group by secid
having TOTAL_SCORE=max(TOTAL_SCORE)
order by secid;
quit;

View solution in original post

1 REPLY 1
novinosrin
Tourmaline | Level 20

You are missing GROUP BY

 

So-

proc sql;
create table max as
select  *
from CRSP_data3
group by secid
having TOTAL_SCORE=max(TOTAL_SCORE)
order by secid;
quit;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

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
  • 1 reply
  • 498 views
  • 1 like
  • 2 in conversation