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;
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;
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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.