Programming the statistical procedures from SAS

Data management using SAS

Accepted Solution Solved
Reply
Contributor
Posts: 24
Accepted Solution

Data management using SAS

Hello Everyone!


I have a dataset where each column represents a day. There are 1825 columns. Each row represents a patient. Each day that the patient had a medication there is a 1 in the column and 0 for the days when the patient took no medication. On the days when the patient took more than one medication, the column has the number of medications taken by the patient on that day (could be 2, 3, etc.) I am interested in identifying patients taking multiple medication (more than 1) on at least 60 consecutive days without a 31 day gap. From the start of the at least 60-day multiple medications episode, I need to follow the patient for a year (365 days). If the patient had multiple episodes within the 365-day period i.e.say 75 days multiple medications, then for 55 days just one medication and then 100 days of multiple medications again, I need to count those episodes, too. I need to report the number of episodes of multiple medications and mean length of each episode.

Please could you help me with the code on this.

This is a snapshot of my dataset.

               day1 day2 day3 day4 day5 day6 day7 day8 day9 day10 day11 day12

Patient1    1      1        1       1     1       2      2      2      2       2        2        2

Patient2     2      2        2       2     2      1      1      1       1      2         2        2

   

Thank you!

Pooja Desai


Accepted Solutions
Solution
‎04-08-2013 09:44 PM
Respected Advisor
Posts: 4,606

Re: Data management using SAS

Not the whole thing, but here is a way to get the list of all multiple medication episodes :

data have;
length patient $ 12;
input patient day1-day15;
datalines;
Patient1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2
Patient2 2 2 2 2 2 1 1 1 1 2 2 2 2 1 1
;

data haveMult(keep=patient dayStart days);
set have;
array d{*} day: Dum;
Dum = -1;
gap = 0;
call missing(dayStart);
do i = 1 to dim(d);
     if missing(dayStart) then do;

          if d{i} > 1 then dayStart = i;

          end;
     else do;
          if d{i} > 1 then do;

               gap = 0;
               end;
          else do;
               gap = gap + 1;
               if gap > 30 or d{i} < 0 then do;
                    days = 1 + i - gap - dayStart;
                    outPut;
                    call missing(dayStart);
                    gap = 0;
                    end;
               end;
          end;
     end;
run;

proc print data=haveMult; run;

PG

PG

View solution in original post


All Replies
Respected Advisor
Posts: 4,606

Re: Data management using SAS

Hi, could you explain further what is meant by "at least 60 consecutive days without a 31 day gap" ? - PG

PG
Contributor
Posts: 24

Re: Data management using SAS

Hello,

By that I mean that for a patient to be classified as taking more than one medication they should have two medications for 60 days one after the other. If there is a gap of less than 31 days (during the gap the patient can be taking one medication or no medication)then that still counts as a part of the multiple medication episode.

Example:

                       d1 d2 d3 d4 d5 d6 d7 d8 d9-d19 d20-30 d31-d41 d42-d52 d53-d58 dd59 d60 d61 d62 d63 d64 d65 d66 d67 d68 d69 d70 d71 d72 d73 d74

Patient1            1   1   1   1  2   2   2   2   2   2    2    2     2    2     2   2    2      2    2     2     2     2     1     1    1    1     1   2     2     2    2      2    2     2

                       

For patient1 once the patient starts taking 2 medications on day 5 he continues doing so till day 75. There are 5 days from day 63 to day 67 where he took only one medication but since it is lesser than 31 days it is counted as a part of the multiple medication episode.


                        d1 d2 d3 d4 d5 d6  d7-d65  d66 d67 d68-d101   d102  d103 d104  d105 d106  d107-d175 d176 d177 d178 d179

Patient2            1    2   2   2  2  2    2    2    2     2    1       1        1       1       1     1        2      2        2     2      2    2      2 

Patient2 uses multiple medications from day 2 till day 67. he then has a gap from day 68 to day 105. Since this is greater than 31 days, when he starts using multiple medications again on day 106 to day 179, this counts as a second episode.

I want to follow the patients for 365 days after their first at least 60-day multiple medication episode. So we would follow patient1 for 365 days after day 5 and patient2 for 365 days after day 2. During this 365 days period, I need to count all the multiple medication episodes which are at least 60 days in length without a gap (gap=when the patient takes 1 or 0 medications) of 31 days or greater. If the patient takes multiple medications for less than 60 days, it is not considered as a multiple medications episode.

I hope this makes it clearer.

Thanks a lot!

Pooja

Solution
‎04-08-2013 09:44 PM
Respected Advisor
Posts: 4,606

Re: Data management using SAS

Not the whole thing, but here is a way to get the list of all multiple medication episodes :

data have;
length patient $ 12;
input patient day1-day15;
datalines;
Patient1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2
Patient2 2 2 2 2 2 1 1 1 1 2 2 2 2 1 1
;

data haveMult(keep=patient dayStart days);
set have;
array d{*} day: Dum;
Dum = -1;
gap = 0;
call missing(dayStart);
do i = 1 to dim(d);
     if missing(dayStart) then do;

          if d{i} > 1 then dayStart = i;

          end;
     else do;
          if d{i} > 1 then do;

               gap = 0;
               end;
          else do;
               gap = gap + 1;
               if gap > 30 or d{i} < 0 then do;
                    days = 1 + i - gap - dayStart;
                    outPut;
                    call missing(dayStart);
                    gap = 0;
                    end;
               end;
          end;
     end;
run;

proc print data=haveMult; run;

PG

PG
Contributor
Posts: 24

Re: Data management using SAS

Hello PG,

Thank you very much. This is awesome! I had another follow-up question on this code.

If

dayEnd=dayStart+365

would it be possible to identify other distinct multiple therapy periods- periods of at least 60 days or more of multiple therapy without a 31 day gap- which occur after a greater than 31 days gap after the identified episode but before the dayEnd.

Thanks again--I really appreciate your help.


Pooja

 

Contributor
Posts: 24

Re: Data management using SAS

Please disregard my previous comment. I see that the situation I mentioned has already been considered! Thank a lot for your help, PGStats, I really appreciate it!!

Pooja

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 214 views
  • 0 likes
  • 2 in conversation