Hello Evolod,
This is a possible solution to your problem. For the data you supplied all patients took less than 3 medications a week.
data a;
input ID 1-6 DRUG $ 8-14 DATE YYMMDD11.;
format date date7.;
datalines;
100001 ADVIL 2010-03-25
100001 TILENOL 2010-04-08
100001 TILENOL 2010-04-10
100001 TILENOL 2010-04-12
100001 TILENOL 2010-04-14
100001 TILENOL 2010-04-28
100001 TILENOL 2010-05-01
100002 ADVIL 2010-04-01
100002 ADVIL 2010-04-09
100002 ADVIL 2010-04-10
100002 ADVIL 2010-04-12
100002 ADVIL 2010-04-14
100002 TILENOL 2010-04-28
100002 TILENOL 2010-05-01
;
run;
/* Add Year, Week */;
data a1;
set a;
yr=YEAR(Date);
wk=WEEK(Date);
run;
/* Check if patient is taking meds more that 3 times a week */;
proc SQL;
create table r as
select ID, yr, wk, Count(*) as n,
case
when calculated n > 3 then ' >3'
else '<=3'
end as result
from a1
group by ID, yr, wk
;quit;
Sincerely,
SPR