Date: Wed, 29 May 2002 18:51:14 -0400
Reply-To: Sigurd Hermansen <HERMANS1@WESTAT.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Sigurd Hermansen <HERMANS1@WESTAT.COM>
Subject: Re: Avg subsets of values in a dataset
Content-Type: text/plain; charset="iso-8859-1"
I don't find any SAS function or format that condenses date values to weeks
of the year. Others may have a better idea of where to look.
A crude but simple solution chops the SAS date sequence into 7-day segments
and computes averages per segment:
data test;
input
date: mmddyy8. value
;
cards;
1/1/01 55
1/3/01 58
1/4/01 59
1/6/01 57
1/7/01 56
1/8/01 72
1/12/01 55
;
run;
proc sql;
select distinct date,floor((date)/7) as yrWeek,avg(value) as avg
from test
group by calculated yrWeek
;
quit;
Since the SAS date value of zero corresponds to a Friday, you may have to
use an offset to normalize the week value to a calendar week.
Sig
-----Original Message-----
From: Gigi Lipori [mailto:pflugg@BELLSOUTH.NET]
Sent: Wednesday, May 29, 2002 5:39 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Avg subsets of values in a dataset
If I have a dataset that looks something like the following:
date value
1/1/01 55
1/3/01 58
1/4/01 59
1/6/01 57
1/7/01 56
1/8/01 72
...
continue same thing for four or five years.
What's the easiest way to grab the 'weekly' averages, as well as highs and
lows for the week. For instance....Week 1/1 through 1/7, I would want to
output a record something like 1/1/01 1/7/01 41 0 59 (consider missing
values to be 0 -- format start day, end day, avg, low, high). Then I'd want
it to pick up for the next 7 days, and so forth.
I know how to do it in VB, but I have trouble following iterations in SAS.
Any help would be appreciated...Gigi