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

Hi All,

 

I have sample data below :- 

 

Account_No   Limit     Score

========     =====    ====

11111              1000     14.34

11111               2000     11.29

22222             1000     18.23

22222              2000     21.01

33333              3000     12.22

33333              1000     12.22 

 

Need to compare the score column values when we have multiple entries for the same account number and keep:-

#1) the lowest score value row for the account number

#2) If the score value is same , then I need to pick up highest limit value row.

 

Output data:-

 

Account_No   Limit     Score

========     =====    ====

11111               2000     11.29

22222             1000     18.23

33333              3000     12.22

 

Can someone suggest me a logic to achieve this ?

Thanks,

Ashok 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

I think a slight variation on the suggested program would work:

 

proc sort data=have;
   by account_no score descending limit;
run;

data want;
   set have;
   by account_no;
   if first.account_no;
run;

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20
proc sort data=your_dataset out=sorted_dsn;

by account_no score;

run;



data want_dsn;

 set sorted_dsn;

by account_no;

if first.account_no;

run;
PGStats
Opal | Level 21

@novinosrin , add descending limit to the sort criteria to fulfill OP second requirement.

PG
novinosrin
Tourmaline | Level 20

Sir @PGStats  Thank you as I failed to notice the 2nd one and went for lunch. Well, @Astounding  has answered it. 

Astounding
PROC Star

I think a slight variation on the suggested program would work:

 

proc sort data=have;
   by account_no score descending limit;
run;

data want;
   set have;
   by account_no;
   if first.account_no;
run;
AshokD
Obsidian | Level 7

Thanks. It makes sense, let me try it out.

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!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 628 views
  • 0 likes
  • 4 in conversation