The following sample program will calculate the average number of patients seen per day for each physician on days where at least two patients where seen.
visits: records of physician visits made over a given period, usually a year;*THE FOLLOWING VARIABLES ARE ASSUMED:
md_id: MD ID, identifies each individual physician*COUNT VISITS OF THE SAME PERSON TO THE SAME PHYSICIAN ON THE SAME DAY ONLY ONCE;
pat_id: Patient ID, identifies each individual patient
visdate: Visit date, the date when the visit occurred
proc sort data=visits nodupkey;*ADD UP TOTAL PATIENTS SEEN ON A GIVEN DAY;
by md_id visdate pat_id;
run;
data visdays;*CALCULATE THE AVERAGE NUMBER OF PATIENT SEEN PER DAY FOR EACH PHYSICIAN;
set visits;
by md_id visdate pat_id;
retain pattot;
if first.visdate then pattot=0;
pattot=pattot+1;
if last.visdate and pattot>1 then output visdays;
*OUTPUT ONE RECORD FOR EVERY DAY EACH PHYSICIAN SAW AT LEAST 2 PATIENTS;
RUN;
proc summary data=visdays nway;
class md_id;
var pattot;
output out=avgpat mean=avgpat;
run;