Date: Tue, 27 Aug 2002 09:10:00 -0400
Reply-To: "Nevseta, Floyd G" <Floyd.G.Nevseta@BANKOFAMERICA.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Nevseta, Floyd G" <Floyd.G.Nevseta@BANKOFAMERICA.COM>
Subject: Re: How to find MAX value corresponding with time.
Content-type: text/plain; charset=iso-8859-1
This response builds on Vanessa's post earlier. If you want to presort the
data, put them in an order that you can easily select the correct obs. For
each county you want the first occurrence of the maximum value. Well, sort
it like this:
proc sort data=table1;
by county descending value valuetime;
run;
Then select your obs like this:
data table2;
set table1;
by county descending value valuetime;
if first.county;
run;
Regards,
Floyd
-----Original Message-----
From: AT [mailto:tangtk@COLUMB31.DHEC.STATE.SC.US]
Sent: Monday, August 26, 2002 5:09 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: How to find MAX value corresponding with time.
I have this dataset:
data Table1;
format ValueTime time8.;
infile cards;
input County $ ValueTime time8. value;
cards;
Alpha 12:00:00 10
Alpha 12:01:00 15
Alpha 12:02:00 15
Beta 12:00:00 17
Beta 12:01:00 6
Beta 12:02:00 12
;
run;
I would like to have a query that returns the County, maximum value
and
the first time that value occurred
County MaxValue MinValueTime
------------------------------------
Alpha 15 12:01:00
Beta 17 12:00:00
.
.
So far I have this and the query returns every date/time for a given
County where the Value happens to be the maximum, when all I want is
the first one.
proc sql noprint;
create table max as
SELECT County, max(Value) as MaxValue, ValueTime
from table1
group by County;
quit;
run;
If there is a better way to work this out, PLMK. Any respones would
be appreicated.
Allie