|
Actually, there is no need to crank up a DATA step view. SQL can create the
week numbers on the fly:
select Week(Date)as Week , Sum(Humidity) as SubTotal
from Weekly
group by Week ;
On the other hand, if that view *is* created, we can forget SQL altogether
and let PROC SUMMARY do both levels of total at once:
proc summary data=aaa;
class week;
var Humidity;
output out=SubTotals_and_Totsals sum=;
run;
On Fri, 31 Mar 2006 05:42:01 +0000, toby dunn <tobydunn@HOTMAIL.COM> wrote:
>Chait ,
>
>You also ddint mention whether you wanted the weeks to start on sunday and
>go 7 days, whether you wanted the seven day count to start on the 1st and a
>week is defined as six days from that date, or if you wanted to use the
>calander.
>
>Also, you never mentioned what the Total was made ofm a cumulative sum by
>week or the whole data set.
>
>And finally you didnt mention ehat version of SAS you have which makes a
>difference in what one can use in the way of functions and how much code it
>will take.
>
>
>So here is a solution which I think can be refactor to run faster and
>assumes version 9 and the Total is the total of humidity for the entire
data
>set:
>
>data weekly ;
>input date mmddyy10. humidity ;
>cards ;
>1/1/2002 1
>1/2/2002 2
>1/3/2002 3
>1/4/2002 4
>1/5/2002 5
>1/6/2002 6
>1/7/2002 7
>1/8/2002 8
>1/9/2002 9
>1/10/2002 10
>1/11/2002 11
>1/12/2002 12
>1/13/2002 13
>1/14/2002 14
>1/15/2002 15
>1/16/2002 16
>1/17/2002 17
>1/18/2002 18
>1/19/2002 19
>1/20/2002 20
>;
>run ;
>
>
>data AAA / view = AAA ;
>set Weekly ;
>Week = Week(Date) ;
>run ;
>
>proc sql ;
>Create table SubTotal as
> select Week , Sum(Humidity) as SubTotal
> from AAA
> group by Week ;
>
>Create table Need as
> select * , Sum(SubTotal) as Total
> from SubTotal ;
>quit ;
>
>
>
>
>Toby Dunn
>
>
>
>
>
>From: chait <v.r.krishnachaitanya@GMAIL.COM>
>Reply-To: chait <v.r.krishnachaitanya@GMAIL.COM>
>To: SAS-L@LISTSERV.UGA.EDU
>Subject: Finding out of weekly sum
>Date: Thu, 30 Mar 2006 20:06:58 -0800
>
>data weekly;
>input date mmddyy10. humidity;
>cards;
>1/1/2002 1
>1/2/2002 2
>1/3/2002 3
>1/4/2002 4
>1/5/2002 5
>1/6/2002 6
>1/7/2002 7
>1/8/2002 8
>1/9/2002 9
>1/10/2002 10
>1/11/2002 11
>1/12/2002 12
>1/13/2002 13
>1/14/2002 14
>1/15/2002 15
>1/16/2002 16
>1/17/2002 17
>1/18/2002 18
>1/19/2002 19
>1/20/2002 20
>;
>run;
>
>Like this there are thousands of data is there in raw file.
>
> We want the weekly sum i.e for every 7 days we want the sum of
>humidity and as well as the total sum.
|