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.
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;
What would you like to do if two observations are tied for the highest or lowest value?
I want to indicate the max and min value of each id value by the 'Y' flag.
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;
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?
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.
thank u.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Get started using SAS Studio to write, run and debug your SAS programs.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.