<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to count unique prescribers per patient in a rolling 365 day period? in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-count-unique-prescribers-per-patient-in-a-rolling-365-day/m-p/267177#M7390</link>
    <description>&lt;P&gt;Sara,&lt;/P&gt;&lt;P&gt;if your data are sorted by id and date, this should work:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mine;
  set pdmp;
  by individual_id;
  format h_date_seen first_date mmddyy10.;
  if first.individual_id then do;
    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;
    else
      prescriber.clear();
  end;
  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;
  if prescriber.num_items&amp;gt;=1 then do;
    first_date=intnx('YEAR',date_dispensed,-1,'SAME');
    rc = i.first();
    do until(i.next());
      if h_date_seen&amp;lt;first_date then
        prescriber.remove();
    end;
  end;
  prov_cnt_back=prescriber.num_items;&lt;BR /&gt;  drop first_date rc h_:;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am not sure how it will stack against your 25 million records, but give it a try!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 29 Apr 2016 08:59:18 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2016-04-29T08:59:18Z</dc:date>
    <item>
      <title>How to count unique prescribers per patient in a rolling 365 day period?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-count-unique-prescribers-per-patient-in-a-rolling-365-day/m-p/265521#M7325</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I'm working in SAS 9.3, W32_7PRO platform on Windows V6.1 operating system.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!!&lt;/P&gt;&lt;P&gt;Sara&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2016 19:53:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-count-unique-prescribers-per-patient-in-a-rolling-365-day/m-p/265521#M7325</guid>
      <dc:creator>sarahallvik</dc:creator>
      <dc:date>2016-04-21T19:53:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to count unique prescribers per patient in a rolling 365 day period?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-count-unique-prescribers-per-patient-in-a-rolling-365-day/m-p/265530#M7327</link>
      <description>Would be nice if you can provide a set of sample on both incoming and outcome data.</description>
      <pubDate>Thu, 21 Apr 2016 21:07:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-count-unique-prescribers-per-patient-in-a-rolling-365-day/m-p/265530#M7327</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2016-04-21T21:07:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to count unique prescribers per patient in a rolling 365 day period?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-count-unique-prescribers-per-patient-in-a-rolling-365-day/m-p/265532#M7328</link>
      <description>&lt;P&gt;The input data looks like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sample;
	input individual_id prescriber_num date_dispensed;
datalines;
1 101 1/1/2012 
1 564 5/1/2012 
1 88 6/15/2012 
1 101 10/4/2012 
1 3351 4/1/2013 
2 1199 5/1/2012 
2 1199 6/1/2012 
2 1199 7/1/2012 
2 1811 8/1/2012 
3 646 4/1/2012 
3 646 5/1/2012 
3 7752 6/1/2012
3 505 7/1/2012 
3 505 8/1/2012 
3 646 4/1/2013 
3 505 5/1/2013 
3 871 5/15/2013 
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want the output data to look like this, where "prov_cnt_back" is the number of unique prescribers in the 365 days prior to the date_dispensed.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data out;
	input individual_id prescriber_num date_dispensed prov_cnt_back;
datalines;
1 101 1/1/2012 1 
1 564 5/1/2012 2 
1 88 6/15/2012 3 
1 101 10/4/2012 3 
1 3351 4/1/2013 4 
2 1199 5/1/2012 1 
2 1199 6/1/2012 1 
2 1199 7/1/2012 1 
2 1811 8/1/2012 2 
3 646 4/1/2012 1 
3 646 5/1/2012 1 
3 7752 6/1/2012 2 
3 505 7/1/2012 3 
3 505 8/1/2012 3 
3 646 4/1/2013 3 
3 505 5/1/2013 3 
3 871 5/15/2013 4
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!! Sara&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2016 21:31:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-count-unique-prescribers-per-patient-in-a-rolling-365-day/m-p/265532#M7328</guid>
      <dc:creator>sarahallvik</dc:creator>
      <dc:date>2016-04-21T21:31:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to count unique prescribers per patient in a rolling 365 day period?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-count-unique-prescribers-per-patient-in-a-rolling-365-day/m-p/265557#M7334</link>
      <description>&lt;P&gt;Here is a 'quick and dirty' SQL approach, it may have performance issue when dealing with huge table. Data step can also achieve the same result, but code could get complex.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sample;
	input individual_id prescriber_num date_dispensed :mmddyy10.;
	format date_dispensed mmddyy10.;
datalines;
1 101 1/1/2012 
1 564 5/1/2012 
1 88 6/15/2012 
1 101 10/4/2012 
1 3351 4/1/2013 
2 1199 5/1/2012 
2 1199 6/1/2012 
2 1199 7/1/2012 
2 1811 8/1/2012 
3 646 4/1/2012 
3 646 5/1/2012 
3 7752 6/1/2012
3 505 7/1/2012 
3 505 8/1/2012 
3 646 4/1/2013 
3 505 5/1/2013 
3 871 5/15/2013 
;
run;

proc sql;
create table want as
select *, (select count(distinct prescriber_num) from sample 
               where individual_id=a.individual_id
                 and date_dispensed between a.date_dispensed and intnx('year',a.date_dispensed,-1,'s')
		   ) as prov_cnt_back

from sample a
;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Apr 2016 23:57:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-count-unique-prescribers-per-patient-in-a-rolling-365-day/m-p/265557#M7334</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2016-04-21T23:57:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to count unique prescribers per patient in a rolling 365 day period?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-count-unique-prescribers-per-patient-in-a-rolling-365-day/m-p/266397#M7359</link>
      <description>&lt;P&gt;Thank you! But with 15 million records to process,&amp;nbsp;the code could not complete the task when left to run for 18 hours. I think a data step is going to be more appropriate... I've been playing around with lag statements, which could work, but is there a way to look back at an unlimited number of previous records for each individual_id?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set sample;
	by individual_id;
		lagdr1 = lag1(prescriber_num);
		lagdr2 = lag2(prescriber_num);
		lagdr3 = lag3(prescriber_num);
		lagdr4 = lag4(prescriber_num);
		lagdr5 = lag5(prescriber_num);
		lagdr6 = lag6(prescriber_num);
		lagdr7 = lag7(prescriber_num);
		lagdr8 = lag8(prescriber_num);
		lagdr9 = lag9(prescriber_num);

	if prescriber_num ne lagdr1 and 
		prescriber_num ne lagdr2 and
		prescriber_num ne lagdr3 and
		prescriber_num ne lagdr4 and
		prescriber_num ne lagdr5 and
		prescriber_num ne lagdr6 and
		prescriber_num ne lagdr7 and
		prescriber_num ne lagdr8 and
		prescriber_num ne lagdr9 then uniquedr = 1;
								else uniquedr = 0;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Apr 2016 14:40:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-count-unique-prescribers-per-patient-in-a-rolling-365-day/m-p/266397#M7359</guid>
      <dc:creator>sarahallvik</dc:creator>
      <dc:date>2016-04-26T14:40:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to count unique prescribers per patient in a rolling 365 day period?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-count-unique-prescribers-per-patient-in-a-rolling-365-day/m-p/266440#M7360</link>
      <description>&lt;P&gt;Sarah,&lt;/P&gt;
&lt;P&gt;Here are some data step code. Please note:&lt;/P&gt;
&lt;P&gt;1. if you have 18M records, and data came as being presented, you only need to upload 3 variables to Hash table, which is roughly 3*8*18million/1024/1024 = 412M bytes, so&amp;nbsp;theoretically if you&amp;nbsp;have Giga&amp;nbsp;+&amp;nbsp;byte memory (which is common), you should be able to fit the whole thing into Hash table. If not, we will have to break it up&amp;nbsp;by ID, and it will take 2XPass, meaning it will take&amp;nbsp;at leaset double&amp;nbsp;amount of time to finish.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. The code can still be tweaked to be more efficient, in theory, such as using Hiter plus SETCUR method, however, I am NOT&amp;nbsp;sure how much leverage you can benefit from it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	if _n_=1 then
		do;
			if 0 then
				set sample;
			dcl hash id(dataset:'sample (keep=individual_id prescriber_num date_dispensed rename=(prescriber_num=_pre date_dispensed=_date))', multidata &amp;amp;colon; 'y');
			id.definekey('individual_id');
			id.definedata('individual_id', '_pre', '_date');
			id.definedone();
			dcl hash pre();
			pre.definekey('_pre');
			pre.definedone();
			call missing(_pre,_date);
		end;

	set sample;
	rc=id.find();
        _beg=intnx('year',date_dispensed,-1,'s');
	do rc=0 by 0 while (rc=0);
		if _beg &amp;lt;=  _date &amp;lt;= date_dispensed then
			rc=pre.add();
		rc=id.find_next();
	end;

	prov_cnt_back=pre.num_items;
	rc=pre.clear();
	drop rc _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Update: To&amp;nbsp;call INTNX() only once per obs instead of up to 365 times, maybe saving your some time.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2016 20:02:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-count-unique-prescribers-per-patient-in-a-rolling-365-day/m-p/266440#M7360</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2016-04-26T20:02:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to count unique prescribers per patient in a rolling 365 day period?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-count-unique-prescribers-per-patient-in-a-rolling-365-day/m-p/267165#M7389</link>
      <description>&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; sample;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;input&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; individual_id prescriber_num date_dispensed &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;mmddyy10.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;format&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; date_dispensed &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;date9.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;datalines&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;1 101 1/1/2012&lt;/P&gt;&lt;P&gt;1 564 5/1/2012&lt;/P&gt;&lt;P&gt;1 88 6/15/2012&lt;/P&gt;&lt;P&gt;1 101 10/4/2012&lt;/P&gt;&lt;P&gt;1 3351 4/1/2013&lt;/P&gt;&lt;P&gt;2 1199 5/1/2012&lt;/P&gt;&lt;P&gt;2 1199 6/1/2012&lt;/P&gt;&lt;P&gt;2 1199 7/1/2012&lt;/P&gt;&lt;P&gt;2 1811 8/1/2012&lt;/P&gt;&lt;P&gt;3 646 4/1/2012&lt;/P&gt;&lt;P&gt;3 646 5/1/2012&lt;/P&gt;&lt;P&gt;3 7752 6/1/2012&lt;/P&gt;&lt;P&gt;3 505 7/1/2012&lt;/P&gt;&lt;P&gt;3 505 8/1/2012&lt;/P&gt;&lt;P&gt;3 646 4/1/2013&lt;/P&gt;&lt;P&gt;3 505 5/1/2013&lt;/P&gt;&lt;P&gt;3 871 5/15/2013&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;sql&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;create&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;table&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; work.out &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;as&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;select&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;s1.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;*, Count(s2.individual_id) + &lt;/FONT&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;as&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; prov_cnt_back&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;from&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; sample s1&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;left&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;join&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; sample s2 &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;on&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;s1.individual_id = s2.individual_id&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;and&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; s1.prescriber_num ~= s2.prescriber_num&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;and&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; s1.date_dispensed - s2.date_dispensed between &lt;/FONT&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;0&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;and&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;365&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;left&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;join&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; sample s3 &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;on&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;s2.individual_id = s3.individual_id&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;and&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; s2.prescriber_num = s3.prescriber_num&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;and&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; s1.date_dispensed - s3.date_dispensed between &lt;/FONT&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;0&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;and&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;365&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;and&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; s3.date_dispensed &amp;lt; s2.date_dispensed&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;where&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; s2.individual_id is &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;null&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; or (s2.individual_id is &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;not&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;null&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;and&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; s3.individual_id is &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;null&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;)&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;GROUP&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;BY&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; s1.individual_id, s1.prescriber_num, s1.date_dispensed;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;This code should work, although you may run into performance issues as you did with the other proc sql code.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;How fast are you expecting this to be?&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Apr 2016 05:04:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-count-unique-prescribers-per-patient-in-a-rolling-365-day/m-p/267165#M7389</guid>
      <dc:creator>azfvftrbhtbetbab</dc:creator>
      <dc:date>2016-04-29T05:04:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to count unique prescribers per patient in a rolling 365 day period?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-count-unique-prescribers-per-patient-in-a-rolling-365-day/m-p/267177#M7390</link>
      <description>&lt;P&gt;Sara,&lt;/P&gt;&lt;P&gt;if your data are sorted by id and date, this should work:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mine;
  set pdmp;
  by individual_id;
  format h_date_seen first_date mmddyy10.;
  if first.individual_id then do;
    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;
    else
      prescriber.clear();
  end;
  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;
  if prescriber.num_items&amp;gt;=1 then do;
    first_date=intnx('YEAR',date_dispensed,-1,'SAME');
    rc = i.first();
    do until(i.next());
      if h_date_seen&amp;lt;first_date then
        prescriber.remove();
    end;
  end;
  prov_cnt_back=prescriber.num_items;&lt;BR /&gt;  drop first_date rc h_:;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am not sure how it will stack against your 25 million records, but give it a try!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Apr 2016 08:59:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-count-unique-prescribers-per-patient-in-a-rolling-365-day/m-p/267177#M7390</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2016-04-29T08:59:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to count unique prescribers per patient in a rolling 365 day period?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-count-unique-prescribers-per-patient-in-a-rolling-365-day/m-p/267298#M7408</link>
      <description>&lt;P&gt;Sara&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an approach.&lt;/P&gt;
&lt;P&gt;Sort by patient ID, script_dt&lt;/P&gt;
&lt;P&gt;Set up an array of prescribers (50) for an Id&amp;nbsp;&amp;nbsp; and hold start script date&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On first.ID clear the prescriber array, start date&lt;/P&gt;
&lt;P&gt;With each obs check the new script_date with the start script date&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; If &amp;lt; 365 check to see if prescriber in array&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; If new prescriber add prescriber to array and add 1 to tot_scripts&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; If tot_scrits gt 4 then set flag&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; If last.ID the output..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To do a rolling 365 over several years, you might want to create a 2 dimensional array and keep the script dates and prescribers for each patient.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Apr 2016 18:03:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-count-unique-prescribers-per-patient-in-a-rolling-365-day/m-p/267298#M7408</guid>
      <dc:creator>Jim_G</dc:creator>
      <dc:date>2016-04-29T18:03:25Z</dc:date>
    </item>
  </channel>
</rss>

