Hello! I am working with a prescription data file, where each row contains a unique patient identifier (individual_id), prescriber identifier (prescriber_num), drug information, and date (date_dispensed). I need to identify patients who receive prescriptions from four or more prescribers in any given 365 day period. My thought was to look back 365 days from every prescription, and count the number of prescribers in that time period, flagging patients that meet the four unqiue prescriber threshold and the date of the prescription at the start of the look-back. Any ideas on how to do this? I've been playing around with a data step with a hash object and proc sql, but to no avail. data mine;
set pdmp;
format h_date_seen mmddyy10.;
by individual_id;
length h_date_seen 8 ;
if _n_ = 1 then do;
declare hash Prescriber();
rc = prescriber.definekey('h_prescriber_num');
rc = prescriber.definedata('h_prescriber_num','h_date_seen');
prescriber.definedone();
dcl hiter i('prescriber');
end;
if first.individual_id then prescriber.clear();
h_prescriber_num = prescriber_num;
if prescriber.find() then do;
h_date_seen = date_dispensed;
prescriber.add();
end;
else do;
h_date_seen = date_dispensed;
prescriber.replace();
end;
presc_Ascend = 0;
rc = i.first();
do while(i.next() = 0);
if prescriber_num ne h_prescriber_num and Date_Dispensed - h_date_seen le 365 then presc_Ascend = 1;
end;
run;
proc print data=mine (obs=20); run;
proc sql;
create table final as
select *,max(presc_cnt_pre,0) as presc_Percent_pre
from (select prescriber_NUM,
count(distinct case presc_Ascend when 1 then individual_id else '' end) as presc_Cnt_pre,
from mine
group by prescriber_NUM);
quit; I'm working in SAS 9.3, W32_7PRO platform on Windows V6.1 operating system. Thank you!! Sara
... View more