Hi:
I suppose there's a more elegant way to do this with INTNX and shift intervals, but at least I can explain this logic.
Using INTNX with the WEEK interval and 'BEGIN' and an increment of 0
[pre]
intnx('week', date, 0, 'begin');
[/pre]
will always take you to a SUNDAY. The trick is that on SUNDAY, you want the MONDAY from the previous week and on MON-SAT, you want the monday from the current week. The program below, I think, does what you want. As I said, there probably is a more elegant way to do it with INTNX. But as you can see from the output in the log, when the date used with INTNX is Oct 1, then the Monday created by this logic is Sept 27.
cynthia
[pre]7942 data testit;
7943 do date='15sep2010'd to '15oct2010'd;
7944 ** intnx of 'week' with 'begin' always goes to SUNDAY;
7945 wdate=intnx('week', date, 0, 'begin');
7946
7947 ** so the wdate + 1 is going to be MONDAY if the day of week is Monday-Saturday;
7948 ** when the day of week is SUNDAY, then you want the PREVIOUS Monday.;
7949 day_of_week = weekday(date);
7950 if day_of_week =1 then monday = wdate-6;
7951 else monday = wdate +1;
7952 putlog date= weekdate28. day_of_week= wdate= weekdate28. monday= weekdate28. ;
7953 if day_of_week = 1 then putlog ' ';
7954 end;
7955 run;
date=Wednesday, Sep 15, 2010 day_of_week=4 wdate=Sunday, Sep 12, 2010 monday=Monday, Sep 13, 2010
date=Thursday, Sep 16, 2010 day_of_week=5 wdate=Sunday, Sep 12, 2010 monday=Monday, Sep 13, 2010
date=Friday, Sep 17, 2010 day_of_week=6 wdate=Sunday, Sep 12, 2010 monday=Monday, Sep 13, 2010
date=Saturday, Sep 18, 2010 day_of_week=7 wdate=Sunday, Sep 12, 2010 monday=Monday, Sep 13, 2010
date=Sunday, Sep 19, 2010 day_of_week=1 wdate=Sunday, Sep 19, 2010 monday=Monday, Sep 13, 2010
date=Monday, Sep 20, 2010 day_of_week=2 wdate=Sunday, Sep 19, 2010 monday=Monday, Sep 20, 2010
date=Tuesday, Sep 21, 2010 day_of_week=3 wdate=Sunday, Sep 19, 2010 monday=Monday, Sep 20, 2010
date=Wednesday, Sep 22, 2010 day_of_week=4 wdate=Sunday, Sep 19, 2010 monday=Monday, Sep 20, 2010
date=Thursday, Sep 23, 2010 day_of_week=5 wdate=Sunday, Sep 19, 2010 monday=Monday, Sep 20, 2010
date=Friday, Sep 24, 2010 day_of_week=6 wdate=Sunday, Sep 19, 2010 monday=Monday, Sep 20, 2010
date=Saturday, Sep 25, 2010 day_of_week=7 wdate=Sunday, Sep 19, 2010 monday=Monday, Sep 20, 2010
date=Sunday, Sep 26, 2010 day_of_week=1 wdate=Sunday, Sep 26, 2010 monday=Monday, Sep 20, 2010
date=Monday, Sep 27, 2010 day_of_week=2 wdate=Sunday, Sep 26, 2010 monday=Monday, Sep 27, 2010
date=Tuesday, Sep 28, 2010 day_of_week=3 wdate=Sunday, Sep 26, 2010 monday=Monday, Sep 27, 2010
date=Wednesday, Sep 29, 2010 day_of_week=4 wdate=Sunday, Sep 26, 2010 monday=Monday, Sep 27, 2010
date=Thursday, Sep 30, 2010 day_of_week=5 wdate=Sunday, Sep 26, 2010 monday=Monday, Sep 27, 2010
date=Friday, Oct 1, 2010 day_of_week=6 wdate=Sunday, Sep 26, 2010 monday=Monday, Sep 27, 2010
date=Saturday, Oct 2, 2010 day_of_week=7 wdate=Sunday, Sep 26, 2010 monday=Monday, Sep 27, 2010
date=Sunday, Oct 3, 2010 day_of_week=1 wdate=Sunday, Oct 3, 2010 monday=Monday, Sep 27, 2010
date=Monday, Oct 4, 2010 day_of_week=2 wdate=Sunday, Oct 3, 2010 monday=Monday, Oct 4, 2010
date=Tuesday, Oct 5, 2010 day_of_week=3 wdate=Sunday, Oct 3, 2010 monday=Monday, Oct 4, 2010
date=Wednesday, Oct 6, 2010 day_of_week=4 wdate=Sunday, Oct 3, 2010 monday=Monday, Oct 4, 2010
date=Thursday, Oct 7, 2010 day_of_week=5 wdate=Sunday, Oct 3, 2010 monday=Monday, Oct 4, 2010
date=Friday, Oct 8, 2010 day_of_week=6 wdate=Sunday, Oct 3, 2010 monday=Monday, Oct 4, 2010
date=Saturday, Oct 9, 2010 day_of_week=7 wdate=Sunday, Oct 3, 2010 monday=Monday, Oct 4, 2010
date=Sunday, Oct 10, 2010 day_of_week=1 wdate=Sunday, Oct 10, 2010 monday=Monday, Oct 4, 2010
date=Monday, Oct 11, 2010 day_of_week=2 wdate=Sunday, Oct 10, 2010 monday=Monday, Oct 11, 2010
date=Tuesday, Oct 12, 2010 day_of_week=3 wdate=Sunday, Oct 10, 2010 monday=Monday, Oct 11, 2010
date=Wednesday, Oct 13, 2010 day_of_week=4 wdate=Sunday, Oct 10, 2010 monday=Monday, Oct 11, 2010
date=Thursday, Oct 14, 2010 day_of_week=5 wdate=Sunday, Oct 10, 2010 monday=Monday, Oct 11, 2010
date=Friday, Oct 15, 2010 day_of_week=6 wdate=Sunday, Oct 10, 2010 monday=Monday, Oct 11, 2010
NOTE: The data set WORK.TESTIT has 1 observations and 4 variables.
[/pre]