This may do what you want, although I am not sure it follows exactly the same rule that you described. /* compute year/week according to this rule: If Jan 1 falls on a Sunday through Wednesday, then the week that includes Jan 1 is week 1. Otherwise the following week is week 1. Then weeks are numbered consecutively up to the last week of the year, which may be a 52 or a 53. */ data date1(keep=cdcweek dth_date); length cdcweek $ 6; do dth_date = '01jan2009'd to '31dec2012'd; year = year(dth_date); yyyy = put(year,4.); pyyy = put(year-1,4.); first_sat = mdy(1,1,year); jan01 = mdy(1,1,year); prevjan01 = mdy(1,1,year-1); do while(weekday(first_sat) ne 7); first_sat = first_sat + 1; end; if dth_date = . then cdcweek = ''; else do; if weekday(jan01) le 4 then do; if dth_date le first_sat then cdcweek = yyyy||"01"; else cdcweek = put(((year*100) + int((dth_date-first_sat-1)/7) + 2),6.); end; else do; if dth_date le first_sat then do; if (weekday(prevjan01) = 4) or ((weekday(prevjan01) = 3) and (jan01-prevjan01 = 366)) then cdcweek = pyyy||"53"; else cdcweek = pyyy||"52"; end; else cdcweek = put(((year*100)+int((dth_date-first_sat-1)/7) + 1),6.); end; /* weekday(jan01) le 4 */ end; /* date missing */ if cdcweek ge 200901 then output; end; /* dth_date from 1/1/2009 to 12/31/2012 */ run;
... View more