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.
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.