|
Kenneth Moody's solution uses the usual date advancing functions. I would
use that too as long as I have a predictable Weekday for the beginning of
the Year. However, It need a small adjustment to make the weeks begin at 1
instead of zero.
If the beginning of the work year is not always a Monday, the following may
be more maintainable:
%let start = "29dec2003"d ;
%let end = "26dec2004"d ;
data weekyear (drop=i);
do date = &start to &end ;
i + 1 ;
week + (mod(i,7)=1) ;
output ;
end ;
format date date9. ;
run ;
There is a test for the mod function and when true a value of 1 gets added
to the existing value of week. The latter is zero to begin with but the
first date tests true so 1 gets added to it. The rest of the first week
tests false and 0 is added to give the entire first week a value of 1. The
logic is repeated for the subsequent assignment of weeks.
Kind Regards,
Venky
On Thu, 15 Apr 2004 09:38:58 -0700, 0101 htns <htns0101@YAHOO.COM> wrote:
>Hi all,
>
>I need help on finding an efficient way to assign 7 days to a week.
>
>Here’s my expected output:
>
>Date Week
>
>29DEC2003 week 1
>
>30DEC2003 week 1
>
>31DEC2003 week 1
>
>01JAN2004 week 1
>
>02JAN2004 week 1
>
>03JAN2004 week 1
>
>04JAN2004 week 1
>
>05JAN2004 week 2
>
>06JAN2004 week 2
>
>07JAN2004 week 2
>
>08JAN2004 week 2
>
>09JAN2004 week 2
>
>10JAN2004 week 2
>
>11JAN2004 week 2
>
>...
>
>10APR2004 week 16
>
>11APR2004 week 16
>
>12APR2004 week 16
>
>13APR2004 week 16
>
>14APR2004 week 16
>
>15APR2004 week 16
>
>...
>
>Essentially, there are 52 weeks in a year. This year, week one starts from
12/29/2003 and week 52 ends on 12/26/2004 (including 12/26/2004)
>
>Any help would be greatly appreciated.
>
>Huong
>
>
>
>
>
>---------------------------------
>Do you Yahoo!?
>Yahoo! Tax Center - File online by April 15th
|