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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.