Date: Tue, 15 Feb 2005 14:47:57 -0500 "Howard Schreier " "SAS(r) Discussion" "Howard Schreier " Re: Sum across weeks

Jack's #2 almost works. Demonstration:

data test; do date = '15dec1999'd, '15dec2004'd; format date weekdate.; do i = 1 to 15; drop i; date = date + round(4*ranuni(1) ); qty = ceil(5*ranuni(1) ); amt = ceil(15*ranuni(1) ); output; end; end; run;

proc means data=test sum; class date; format date weekv5.; run;

However, in the (unlikely) event that the series span 100 years or more, there is trouble. To see this, change 1999 to 1904 in the above code and re-run. Weeks 100 years apart are not properly distinguished, because internally a two-digit year representation is used within the formatted values.

On Tue, 15 Feb 2005 00:58:09 -0800, Jack Hamilton <jfh@STANFORDALUMNI.ORG> wrote:

>At 06:56 pm 2/14/2005 -0500, Diana wrote: > >>I need to sum product \$ & # across weeks. Not sure how to make the program >>change the date without using If/then statements. >> >>Here is some sample code >> >> >>Item_name qty Amt Order_date Launch_date start_date >>tax 2 125 01/12/05 12/21/04 08/01/04 >>act 1 89 02/03/05 01/14/05 08/01/04 >>contractor 1 250 01//4/05 10/05/04 08/1/04 >>tax 1 75 01/12/05 09/21/04 08/01/04 >>act 1 89 02/03/05 11/12/05 08/01/04 >>proseries 1 600 01//4/05 02/01/05 08/1/04 >> >> >>So every 7 days I want to generate a total on qty and Amt. The totals are >>not cumulative. > >Where do you want these results? An output summary data set? An output >detail data set? An output summary report? An output detail report? All >of the above? Some combination? How do you define week? There are at >least 7 different definitions of "week". > >Suggestion 1: Add a new variable containing the week number (use the intck >function), and use that as the class variable in PROC SUMMARY, the GROUP BY >variable in PROC SQL, or the GROUP or ORDER variable in PROC REPORT. > >Suggestion 2: I was going to suggest that you use the WEEKV. format or one >of its relatives in PROC SUMMARY or PROC REPORT, but there doesn't seem to >be a built-in format that displays a 4-digit year and a 2-digit week, and >you can't build one with PROC FORMAT because there's no documented way to >get a zero-filled 2-digit week number, only a varying-length week >number. Careless of them to leave that out, perhaps. > > > > >----- >Jack Hamilton >jfh@alumni.stanford.org >Sacramento, California

Back to: Top of message | Previous page | Main SAS-L page