calculating number of visits in the prior 6 months

Reply
Occasional Contributor
Posts: 10

calculating number of visits in the prior 6 months

Hello,

  I'm trying to use a nested do loop to calculate the number of medical visits in the prior six months.

The first loop places a target date (placeholder) - six months prior to the medical date.  The inner loop would add the number of visits up until the placeholder date and then enter those number of visits into a third array -numvisits6mon.  I could then reset the placeholder date for the next outer loop.   Any help would be much appreciated.

Thx

data new4; set new3;

array targetdate {143} targetdate1 -- targetdate143;

array meddates {143} medicaldate_1 -- medicaldate_143;

array numvisits6mon {143};

placeholder =0;

format placeholder mmddyy10.;

numsum = 0;

do i = 1 to 142;

      if meddates {i} ne . then do;

            placeholder = targetdate (i);

      do j = 1 to 142;

            if meddates (j) ne . then do;

            numsum= numsum + 1;

            if meddates (j) ge placeholder then

            numvisits6mon {j} = 1;

            placeholder = 0;

               end;

      end;

end;

end;

run;

Super Contributor
Posts: 1,636

Re: calculating number of visits in the prior 6 months

Is it possible for you to post some sample data and desired output?

Super User
Posts: 19,789

Re: calculating number of visits in the prior 6 months

I agree with a sample of your data is important, because the solutions are vastly different if your data is long vs wide.

It looks like yours is wide, but always good to verify.

Occasional Contributor
Posts: 10

Re: calculating number of visits in the prior 6 months

Thank you very much! 

Yes, it is in a wide format.  Medical dates are listed per paitent as such:

meddate1

meddate2

medate4

pt1

1/12/12

6/12/12

7/12/11

8/12/11

pt22/2/102/11/103/16/1010/16/10

     

I was thinking the output variable would be wide as well and add the number of visits between meddate within the past 6 months.  For example:  

numvisits1

numvisits2

numvisits3

numvisits4

pt1

1

2

2

3

pt21231

So for pt 1 at first visit, only one in last six months, at meddate2 and ge 6 months, had 1 prior visit and the current visit, total is 2.  At 3rd meddate still two visits because first meddate is out of range.  At 4th medical visit the pt records 3 visits in the past 6 month.  Patient 2 follows the same method for calculating previous 6 months visits.

Hope this helps to clarify..

Occasional Contributor
Posts: 10

Re: calculating number of visits in the prior 6 months

apologies the year for medical visit date for pt1 is incorrect at visit 3 and 4. Correction below

meddate1

meddate2

meddate3

medate4

pt1

1/12/12

6/12/12

7/12/12

8/12/12

pt2

2/2/10

2/11/10

3/16/10

10/16/10

Super User
Posts: 19,789

Re: calculating number of visits in the prior 6 months

I sort of understand what you want, but question how you're going to analyze it and what value it would be.

It doesn't seem like it takes into account the duration appropriately, unless you're looking for 180 day revisits I guess.

Occasional Contributor
Posts: 10

Re: calculating number of visits in the prior 6 months

Well the final analysis is going to be based on "engagement in care."  So if a person had at least 2 visits in the prior 6 months we can categorize them as "engaged."  If they didn't have at least 2 visits in the prior six months they would be categorized as "out of care."

Super User
Posts: 19,789

Re: calculating number of visits in the prior 6 months


Well the final analysis is going to be based on "engagement in care."  So if a person had at least 2 visits in the prior 6 months we can categorize them as "engaged."  If they didn't have at least 2 visits in the prior six months they would be categorized as "out of care."

prior 6 months is what?

Prior to previous visit?

I'm still confused but having a hard time explaining it...

Patient 1 as of Visit 3 - 2 visits in prior 6 months

Patient 2 as of               Visit 3 - 3 visits in prior 6 months

But the second patient all visits encompass a 2 month period, whereas for the 1st patient it covers 7 months. It seems difficult to compare those equivalently. 

Occasional Contributor
Posts: 10

Re: calculating number of visits in the prior 6 months

Yes, you are correct.  Additionally the patient visits have to be at least 60 days apart to be categorized as "engaged in care."

So. "Engaged in care" = 2 or more visits, at least 60 days apart, in the prior 6 months. 

Super User
Posts: 19,789

Re: calculating number of visits in the prior 6 months

Well, I need to go to the doctors Smiley Happy so I can't really help anymore today.

But can you clarify are you still looking for the prior 6 months or engaged in care calculation? If engaged in care, you may want to elaborate more.

Your original question is do-able just didn't make sense to me.

Occasional Contributor
Posts: 10

Re: calculating number of visits in the prior 6 months

:smileygrin: Ok thank you... Good luck at the doctor.  I'm here all day tomorrow as well...

We actually need to calculate the later, the "Engaged in Care" calcuation.  I thought I would first calculate the total number of visits in the prior 6 months and then tease out the ones that weren't at least 60 days apart. 
But this is our official criterion for "Engaged in care" = 2 or more visits, at least 60 days apart, in the prior 6 months.

Will also probably have to take into account if there were zero visits within that time frame as well.  We have data from 2007 through 2012.  

Super Contributor
Posts: 644

Re: calculating number of visits in the prior 6 months

Does it count if there are 3 visits at 40 days apart (ie first and last are > 60 days)?

Sounds to me like you need the first and last visit dates within the 6 month period (end date to be specified) and to calculate the time between.  This will work even if you have only 1 visit (first = last => 0 days => not engaged).

Richard

Occasional Contributor
Posts: 10

Re: calculating number of visits in the prior 6 months

Posted in reply to RichardinOz

Hi,

   Yes, you are correct, it's the first and last date in a 6 month period, it wouldn't matter about the other visits.  As for the end date I was trying to use the current medical date being calculated as the end date.  So the end date would vary for each person depending on the current medical date being calculated.


Super Contributor
Posts: 1,636

Re: calculating number of visits in the prior 6 months

not efficient, but get what you want:

data have;

input id$ (meddate1-meddate4)(:mmddyy8.);

format meddate1-meddate4 mmddyy8.;

cards;

pt1 1/12/12 6/12/12 7/12/12 8/12/12

pt2 2/2/10 2/11/10 3/16/10 10/16/10

;

data temp;

  set have;

  array _d(*) meddate1-meddate4;

  do i=1 to dim(_d);

  date=_d(i);

  output;

  end;

  keep id date;

  format date mmddyy8.;

run;

  proc sql;

    create table want as

   select a.id,a.date ,count(b.date) as d2

     from temp as a,temp as b

   where a.id=b.id and b.date between a.date-180 and a.date

           group by a.id,a.date;

   

proc transpose data=want out=final(drop=_Smiley Happy prefix=numvisits;

var d2;

by id;

run;

proc print;run;

     Obs    id     numvisits1    numvisits2    numvisits3    numvisits4

         1     pt1         1             2             2             3

         2     pt2         1             2             3             1

Super Contributor
Posts: 644

Re: calculating number of visits in the prior 6 months

Are you trying to ascertain whether the patient can currently or at some specified date be regarded as engaged, or was engaged as at the date of the last visit, or could be regarded as engaged at any time over the period for which you have records?  Potentially three different results.  My bet would be that the first definition is the required one, for consistency, rather than the second which you imply in your response (are you really interested in engagement if the last visit was more than 6 months ago?).

If you are sure the second definition is required then you have to step backwards through your array to determine the last visit date and then keep going backwards until you find any visit between 60 and 180 days previously.

If I am right you need to do the same, but reject any result where the last date is outside the 180 day window set by the review end date.

Richard

Ask a Question
Discussion stats
  • 15 replies
  • 868 views
  • 0 likes
  • 4 in conversation