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

hi all,

I have a data set like this.

 

id  value
101  93
101  92
101  91
102  32
102  23
102  51
103  45
103  63
103  77

 

Whai I requires is to flag the minimum and max values out of this 3 values like:

 

id  value  min    max
101  93             Y
101  92
101  91     Y
102  32
102  23     Y
102  51             Y
103  45     Y
103  63
103  77             Y

 

someone please post the soln.thanks.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Hmmm... not exactly an answer.  So based on one way to interpret the result:

 

proc sort data=have;

by id value;

run;

 

data want;

set have;

by id;

if first.id then min='Y';

if last.id then max='Y';

run;

View solution in original post

6 REPLIES 6
Astounding
PROC Star

What would you like to do if two observations are tied for the highest or lowest value?

AKHILA
Obsidian | Level 7

 I want to indicate the max and min value of each id value by the 'Y' flag.

Astounding
PROC Star

Hmmm... not exactly an answer.  So based on one way to interpret the result:

 

proc sort data=have;

by id value;

run;

 

data want;

set have;

by id;

if first.id then min='Y';

if last.id then max='Y';

run;

AKHILA
Obsidian | Level 7

 This is correct but I don't want to change the order of id by proc sort because there are some more variable are there . I mean without sorting can we do it?

Astounding
PROC Star

OK, without sorting (but assuming that the data is currently in order by ID):

 

data want;

do until (last.id);

   set have;

   by id;

   minval = min(minval, value);

   maxval = max(maxval, value);

end;

do until last.id;

   set have;

   by id;

   min = ' ';

   max = ' ';

   if value = minval then do;

      min = 'Y';

      minval = ._;   /* prevent another match from being found */

   end;

   if value = maxval then do;

      max = 'Y';

      maxval = ._;

   end;

   output;

end;

drop minval maxval;

run;

 

It's untested code, so you will need to try it and see if the results meet your needs.

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

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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