Hi Peter_C, Thanks for you answer. I am not quite sure how to do this as it is a date range. My code looks like this but returns several observations for some weeks, when the days are overlapping: data mydata ;
set mydata;
by ID FROM TO;
format GFROM
GTO
FROM
TO
WEEKDATX17.;
GFROM=FROM;
GTO=TO;
WEEKFROM=week(GFROM,'v');
WEEKTO=week(GTO,'v');
/* Dividing observations to weeks; */
FROM=intnx('week',GFROM, 0, 'b')+1; /* Monday*/
TO=intnx('week',GFROM, 0, 'e')+1; /* Sunday */
if FROM<GFROM then FROM=GFROM;
if TO>GTO then TO=GTO;
if FROM>GTO then delete;
if TO<GFROM then delete;
WEEK_NR=week(FROM,'v');
days_from_event=intck('day',EVENT,FROM);
weeeks_from_event=intck('week', EVENT,FROM);
output;/* week 1 */
FROM=intnx('week',GFROM, 1, 'b')+1;
TO=intnx('week',GFROM, 1, 'e')+1;
if FROM<GFROM then FROM=GFROM;
if TO>GTO then TO=GTO;
if FROM>GTO then delete;
if TO<GFROM then delete;
WEEK_NR=week(FROM,'v');
days_from_event=intck('day',EVENT,FROM);
weeeks_from_event=intck('week', EVENT,FROM);
output;/* week 2 */
... /*same until week 5 */
run;
... View more