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

Hi All,

I do not know how to use MAX IF function in SAS EG so that I can get the following output.

Given the left two columns, how can I get the output table (table only, not report) like below? Prefer using EG Query Builder, if cannot, code is also good for me. Thank you so much! Smiley Happy

SchoolScoreMax Score of the SchoolMin Score of the School
IT989870
Biz809980
Biz889980
Law979784
IT709870
Law849784
IT789870
Biz999980
Law869784
1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

The easiest point-and-click method is two queries: first to calc the Min/Max for each school group, then the second to join that result with the original detail.

In screen shots, with this data:

data scores;
infile datalines dsd delimiter=' ';
length school $ 3 score 8;
input school score;
datalines;
IT 98
Biz 80
Biz 88
Law 97
IT 70
Law 84
IT 78
Biz 99
Law 86
run;

STEP 1:

minmax.png

STEP 2:

join.png

The flow:

flow.png

Result:

result.png

Chris

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!

View solution in original post

2 REPLIES 2
ChrisHemedinger
Community Manager

The easiest point-and-click method is two queries: first to calc the Min/Max for each school group, then the second to join that result with the original detail.

In screen shots, with this data:

data scores;
infile datalines dsd delimiter=' ';
length school $ 3 score 8;
input school score;
datalines;
IT 98
Biz 80
Biz 88
Law 97
IT 70
Law 84
IT 78
Biz 99
Law 86
run;

STEP 1:

minmax.png

STEP 2:

join.png

The flow:

flow.png

Result:

result.png

Chris

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
AmberLOL
Calcite | Level 5

Hi Chirs,

Thank you very much. I found that actually just the second step is enough. MAX(score) Group by school.

ThanksSmiley Happy

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 2 replies
  • 2899 views
  • 0 likes
  • 2 in conversation