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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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