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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.