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.

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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