Hello Everyone , i'm new with SaS , and i have this dataset :
| User | Orders | Fam | Size |
| 2563 | 1542 | 66 | 4 |
| 2563 | 2251 | 66 | 5 |
| 2563 | 1544 | 66 | 6 |
| 2563 | 2222 | 28 | 2 |
| 2563 | 2335 | 28 | 1 |
AND i want to get the maximum of the size for each user , like the output would be like this :
| User | fam_Max | Szie_Max |
| 66 | 6 | |
| 2563 | 28 | 2 |
Can anyone give me hand ? , that would be great , thank you.
The sample output you provided doesn't really get the maximum size for each User, but for each Fam.
Here is code to achieve the same output:
proc sql;
create table want as(
select distinct a.User
,max(a.Fam) as Max_of_Fam
,max(a.Size) as Max_of_Size
from have a
group by a.Fam
);
quit;If you want the maximum size for each User:
proc sql;
create table want as(
select a.User
,max(a.Fam) as Max_of_Fam
,max(a.Size) as Max_of_Size
from have a
group by a.User
);
quit;
One way
data have;
input User Orders Fam Size;
datalines;
2563 1542 66 4
2563 2251 66 5
2563 1544 66 6
2563 2222 28 2
2563 2335 28 1
;
proc summary data=have nway;
class fam;
var Size;
output out=want(drop=_:) max=;
run;
The sample output you provided doesn't really get the maximum size for each User, but for each Fam.
Here is code to achieve the same output:
proc sql;
create table want as(
select distinct a.User
,max(a.Fam) as Max_of_Fam
,max(a.Size) as Max_of_Size
from have a
group by a.Fam
);
quit;If you want the maximum size for each User:
proc sql;
create table want as(
select a.User
,max(a.Fam) as Max_of_Fam
,max(a.Size) as Max_of_Size
from have a
group by a.User
);
quit;
Thank You.
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.