BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Midi
Obsidian | Level 7

Hello Everyone , i'm new with SaS , and i have this dataset :

 

UserOrdersFamSize
25631542664
25632251665
25631544666
25632222282
2563233528

1

 

AND i want to get the maximum of the size for each user , like the output would be like this :

 

Userfam_MaxSzie_Max
 666
2563282

 

Can anyone give me hand ? , that would be great , thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
sustagens
Pyrite | Level 9

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;

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

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;
sustagens
Pyrite | Level 9

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;
Midi
Obsidian | Level 7

Thank You.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1065 views
  • 0 likes
  • 3 in conversation