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
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.