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

 Given Data: 

 

Id             Name               Amount
1            Blue                   $30
1               red                  $15
1            Green                  $23
1           Orange                $10

2...

 

I want to create a new column where I need only min value name orange, as the min total amount is $10.

Max function not working for new column as it is sorting in alphabetical order(Character variable). Any way to do it in single data step without joining ? 

I tried with case statement too.

 

Id            Name             Amount      Newcol
1           Blue                 $30             Orange
1            red                  $15             Orange
1           Green               $23            Orange
1           Orange             $10              Orange

 

proc sql;
create table want as
select id, Name,min(Amount) as Min_Tot,
max(Amountt) as Max_Tot, min(name) as Min_name
from table have;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
kiranv_
Rhodochrosite | Level 12

something like this

proc sql;
create table want as
select a.*,b.new_col from 
(select * from have)a
inner join
(select id, name as new_col from have
group by ID
having amount =min(amount))b
on a.id =b.id;

View solution in original post

2 REPLIES 2
kiranv_
Rhodochrosite | Level 12

something like this

proc sql;
create table want as
select a.*,b.new_col from 
(select * from have)a
inner join
(select id, name as new_col from have
group by ID
having amount =min(amount))b
on a.id =b.id;
Kalai2008
Pyrite | Level 9
Thank you It worked!

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!

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
  • 2 replies
  • 793 views
  • 1 like
  • 2 in conversation