Learning SAS? Welcome to the exclusive online community for all SAS learners.

Checking number of visits over time within a 2 yr period

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Checking number of visits over time within a 2 yr period

I have a situation where patients have multiple physician visits over time. To be qualified they need to have at least 4 visits during a 2 year period of time starting with first visit. If starting with the first visit and there are less than 4 visits during the 2 yrs then start with the second visit and keep looking until they qualify. Any suggestions please.
Thank you
Phil

Accepted Solutions
Solution
3 weeks ago
Super User
Posts: 5,359

Re: Checking number of visits over time within a 2 yr period

[ Edited ]

Assuming your visit date variable is a SAS date, this gives you a list of qualified patients ...

 

proc sort data=have;

by patient visit_dt;

run;

 

data want;

set have;

by patient;

if first.patient then do;

   qualfied='N';

   n_visits = 1;

end;

else n_visits + 1;

duration = dif3(visit_dt);

if n_visits >= 4 and duration <= 730 then qualified='Y';

retain qualified;

if last.patient;

run;

 

Hope it's acceptable to use 730 days as the measurement, and ignore leap years.

 

********************************

EDITED:

 

@mkeintz you're absolutely right.  Correction is in place now.  Thanks.

View solution in original post


All Replies
Frequent Contributor
Posts: 132

Re: Checking number of visits over time within a 2 yr period

Is the patient visit data short and wide or long and narrow? In other words, In your data, do you have an observation (row) for every patient visit, or do you have multiple variables in the same patient row for multiple visits? 

New Contributor
Posts: 3

Re: Checking number of visits over time within a 2 yr period

Thank you for the response, 

My data is long, one patient has multiple observations with distinct visit dates.

 

PAt_id visit

101   date1

101   date2

101   date3

105   date1

105    date2

105   date3  and so on..

  

Solution
3 weeks ago
Super User
Posts: 5,359

Re: Checking number of visits over time within a 2 yr period

[ Edited ]

Assuming your visit date variable is a SAS date, this gives you a list of qualified patients ...

 

proc sort data=have;

by patient visit_dt;

run;

 

data want;

set have;

by patient;

if first.patient then do;

   qualfied='N';

   n_visits = 1;

end;

else n_visits + 1;

duration = dif3(visit_dt);

if n_visits >= 4 and duration <= 730 then qualified='Y';

retain qualified;

if last.patient;

run;

 

Hope it's acceptable to use 730 days as the measurement, and ignore leap years.

 

********************************

EDITED:

 

@mkeintz you're absolutely right.  Correction is in place now.  Thanks.

Valued Guide
Posts: 947

Re: Checking number of visits over time within a 2 yr period

@Astounding  I think you need dif3, not dif4.

New Contributor
Posts: 3

Re: Checking number of visits over time within a 2 yr period

Thank you for sharing this , I will try the SAS code.
Appreciate your help!
☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 209 views
  • 2 likes
  • 4 in conversation