I am trying to get the below output in Proc SQL, instead of first. and last.variable. But not getting the desired output using min/max function.
Given Data | Output | ||||||
Name | Id | Value | Name | Id | Value | ||
John | 101 | 10 | John | 101 | 10 | ||
John | 201 | 20 | John | 201 | 20 | ||
John | 301 | 30 | John | 301 | 30 | ||
Kate | 201 | 10 | Kate | 201 | 30 | ||
Kate | 201 | 20 | Bob | 101 | 20 | ||
Kate | 201 | 30 | Bob | 201 | 30 | ||
Bob | 101 | 10 | |||||
Bob | 101 | 20 | |||||
Bob | 201 | 30 |
Thanks for looking!
A slight variation:
proc sql;
create table want as
select
name,
id,
max(value) as value
from have
group by name, id;
quit;
8
proc sql;
create table want as
select *
from have
group by name,id
having value=max(value);
quit;
A slight variation:
proc sql;
create table want as
select
name,
id,
max(value) as value
from have
group by name, id;
quit;
8
something like this.
proc sql;
create table want as
select name , id , max(value) as value
from have
group by 1, 2;
Thank you..It worked
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.