SAS - determining time periods of medication use as well as time periods of no medication use

StackOverflow https://stackoverflow.com/questions/21758290

  •  11-10-2022
  •  | 
  •  

Question

I am workin with prescription claims data. Subject X has 20 rows showing the dates he filled his prescriptions. Upto observation 5 he fills his prescription monthly. This is time bloc 1. The next observation has a fill date of 2 years later and has monthly fills for the next 15 rows. This is time bloc 2.

Question: How can I calculate the time on medication for each time bloc? I do not want to include the 2 year time frame that subject x is not filling his prescription.

No correct solution

OTHER TIPS

It can be done in two steps: first, we "mark down" blocks; then group them. Your dataset should be presorted bu subject and date (ascending).

data have2;
     set have;
     by Subject;
     if Date-lag(Date)>30 then Block+1;
     if FIRST.Subject then Block=1;
run;

proc sql;
    create table blocks as
    select Subject, Block, max(Date)-min(Date) as Duration
    from have2
    group by Subject, Block;
quit;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top