Solved
New Contributor
Posts: 4

# 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
‎09-27-2017 04:51 PM
Super User
Posts: 6,785

## 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.

All Replies
Frequent Contributor
Posts: 136

## 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: 4

## 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
‎09-27-2017 04:51 PM
Super User
Posts: 6,785

## 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.

Posts: 1,345

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

@Astounding  I think you need dif3, not dif4.

New Contributor
Posts: 4