BookmarkSubscribeRSS Feed
WorkUser
Obsidian | Level 7

I have the following dataset:

 

ID

NAME

AMOUNT

251717

Better Inc

$5

251717

Better Co

$24

252534

Pan Holdings

$520

252534

Pan Co

$820

259169

Province Inc

$300

259992

ABC Inc

$620

 

Is there a way in SAS EG query builder to create a new computed column called NEWNAME that when IDs are the same, to take the Name with the most amount? So the output would look like this following:  

 

ID

NEWNAME

AMOUNT

251717

Better Co

$29

252534

Pan Co

$1,340

259169

Province Inc

$300

259992

ABC Inc

$620

 

Thanks

2 REPLIES 2
Kurt_Bremser
Super User

A little coding will be much easier than fiddling with the query builder:

proc sort data=have;
by id descending amount;
run;

data want;
set have (rename=(name=_name amount=_amount));
by id;
retain name amount;
if first.id
then do;
  name = _name;
  amount = _amount;
end;
else amount + _amount;
if last.id;
drop _:;
run;
SAS_V_R
Calcite | Level 5

I use EG. You can dabble with the calculator, go to Advanced Functions and mess around with the functions. 

SAS_V_R_0-1680021235145.png

 

Otherwise, Drag the variable column name into select, then press the calculator thing. and identify the variable from its "source column like 't1'. or something like that and make an input statement.

 

Also, find out if you can make a case statement.

 

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

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 2 replies
  • 856 views
  • 0 likes
  • 3 in conversation