<?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: Medication fill code conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Medication-fill-code-conditions/m-p/827480#M326880</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See below for corrected datalines.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Example 1, Original data&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have(label='Prescription Data');
   /*length id $7;*/
   infile datalines truncover;
   input patient_id:$4. med_name:$10. med_fill_date:MMDDYY8.;
   format med_fill_date: mmddyy8.;
Datalines;
123 B_pharmacy 1/9/19
123 B_clinic 1/11/19
123 B_clinic 1/11/19
123 B_clinic 1/11/19
123 B_other 1/17/19
123 B_pharmacy 2/7/19
123 B_clinic 2/8/19
;
proc sort;
 by patient_id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;What the data should look like for Example 1:&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;TABLE width="275"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="87"&gt;patient_id&lt;/TD&gt;
&lt;TD width="87"&gt;med_name&lt;/TD&gt;
&lt;TD width="101"&gt;med_fill_date&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;123&lt;/TD&gt;
&lt;TD&gt;B_pharmacy&lt;/TD&gt;
&lt;TD&gt;1/9/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;123&lt;/TD&gt;
&lt;TD&gt;B_pharmacy&lt;/TD&gt;
&lt;TD&gt;2/7/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Example 2, Original data&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have(label='Prescription Data');
   /*length id $7;*/
   infile datalines truncover;
   input patient_id:$4. med_name:$10. med_fill_date:MMDDYY8.;
   format med_fill_date: mmddyy8.;
Datalines;
155 B_pharmacy 4/4/19
155 B_clinic 4/11/19
155 B_pharmacy 4/29/19
155 B_pharmacy 5/16/19
155 B_clinic 5/16/19
155 B_pharmacy 7/8/19
155 B_pharmacy 9/3/19
155 B_clinic 9/6/19
;
proc sort;
 by patient_id;
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;&lt;STRONG&gt;What the data should look like for Example 2:&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="275"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="87"&gt;patient_id&lt;/TD&gt;
&lt;TD width="87"&gt;med_name&lt;/TD&gt;
&lt;TD width="101"&gt;med_fill_date&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;155&lt;/TD&gt;
&lt;TD&gt;B_pharmacy&lt;/TD&gt;
&lt;TD&gt;4/4/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;155&lt;/TD&gt;
&lt;TD&gt;B_pharmacy&lt;/TD&gt;
&lt;TD&gt;4/29/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;155&lt;/TD&gt;
&lt;TD&gt;B_pharmacy&lt;/TD&gt;
&lt;TD&gt;5/16/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;155&lt;/TD&gt;
&lt;TD&gt;B_pharmacy&lt;/TD&gt;
&lt;TD&gt;7/8/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;155&lt;/TD&gt;
&lt;TD&gt;B_pharmacy&lt;/TD&gt;
&lt;TD&gt;9/3/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To answer your questions&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Do you actually have a&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;&lt;STRONG&gt;single variable&lt;/STRONG&gt;&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;(med_name in your example) that contains&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;&lt;STRONG&gt;both the medicine name and the site&lt;/STRONG&gt;&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;where the prescription is filled?&amp;nbsp; Very poor data design if so, and it makes performing the specific task you request messier that it should be.&lt;STRONG&gt;&lt;EM&gt; We have a single variable that has just the medication name, which we are able to determine whether it's from the pharmacy or clinic; so yes, it is encapsulated into one variable.&lt;/EM&gt;&lt;/STRONG&gt;&lt;/LI&gt;
&lt;LI&gt;What if the first prescription is followed by a second prescription for the same medication and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;&lt;STRONG&gt;filled at the same site&lt;/STRONG&gt;&lt;/EM&gt;?&amp;nbsp; Is that also subject to the 14-day minimum gap requirement, the same as having different sites? &lt;EM&gt;&lt;STRONG&gt;If it's filled at the same site,&amp;nbsp; it is not subject to the 14-day minimum gap requirement. Here is my original description of the problem:&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;A person might be prescribed “B” medication, either at a pharmacy or at a clinic (in no particular order), or another medication entirely. For cases when “B” medication is prescribed, there is a risk of double counting if the medication is prescribed at both a pharmacy and clinic within a 14-day period. Therefore, I want to delete either a pharmacy fill or clinic fill of “B” medication if they occur within 14-days of one another. In such cases, we want to keep the first row/medication fill date of either the pharmacy or clinic prescription of the same medication (and delete what we have defined as duplicates). The risk of double counting occurs only when the same medication is prescribed at both the pharmacy and clinic within this time. If we see just pharmacy prescriptions or just clinic prescriptions, this requirement does not hold.&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;/LI&gt;
&lt;/OL&gt;</description>
    <pubDate>Sat, 06 Aug 2022 23:49:59 GMT</pubDate>
    <dc:creator>alaxman</dc:creator>
    <dc:date>2022-08-06T23:49:59Z</dc:date>
    <item>
      <title>Medication fill code conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Medication-fill-code-conditions/m-p/827471#M326872</link>
      <description>&lt;P&gt;Hello All, In the attached excel sheet, I present data on two examples of two different patients. I have data on patient ID, medication name, and medication fill date. A person might be prescribed “B” medication, either at a pharmacy or at a clinic (in no particular order), or another medication entirely. For cases when “B” medication is prescribed, there is a risk of double counting if the medication is prescribed at both a pharmacy and clinic within a 14-day period. Therefore, I want to delete either a pharmacy fill or clinic fill of “B” medication if they occur within 14-days of one another. In such cases, we want to keep the first row/medication fill date of either the pharmacy or clinic prescription of the same medication (and delete what we have defined as duplicates). The risk of double counting occurs only when the same medication is prescribed at both the pharmacy and clinic within this time. If we see just pharmacy prescriptions or just clinic prescriptions, our logic does not hold.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What would be the most efficient way in either SAS or SQL to handle this?&amp;nbsp; Thank you so much for any guidance that you might be able to provide!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 06 Aug 2022 18:52:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Medication-fill-code-conditions/m-p/827471#M326872</guid>
      <dc:creator>alaxman</dc:creator>
      <dc:date>2022-08-06T18:52:38Z</dc:date>
    </item>
    <item>
      <title>Re: Medication fill code conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Medication-fill-code-conditions/m-p/827472#M326873</link>
      <description>&lt;P&gt;I will not download Excel files and then rely on the vagaries of PROC IMPORT.&lt;/P&gt;
&lt;P&gt;Please post usable example data as a data step with datalines, as shown &lt;A href="https://communities.sas.com/t5/SAS-Programming/Need-help-with-code-calculating-proportion-of-days-covered-by/m-p/763949/highlight/true#M241950" target="_blank" rel="noopener"&gt;here&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Sat, 06 Aug 2022 19:22:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Medication-fill-code-conditions/m-p/827472#M326873</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-08-06T19:22:06Z</dc:date>
    </item>
    <item>
      <title>Re: Medication fill code conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Medication-fill-code-conditions/m-p/827474#M326875</link>
      <description>&lt;P&gt;Here is what the data looks like:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Example 1:&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Original data&lt;/STRONG&gt;&lt;/P&gt;
&lt;TABLE width="334"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="87"&gt;patient_id&lt;/TD&gt;
&lt;TD width="143"&gt;med_name&lt;/TD&gt;
&lt;TD width="104"&gt;med_fill_date&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;123&lt;/TD&gt;
&lt;TD&gt;B_pharmacy&lt;/TD&gt;
&lt;TD&gt;1/9/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;123&lt;/TD&gt;
&lt;TD&gt;B_clinic&lt;/TD&gt;
&lt;TD&gt;1/11/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;123&lt;/TD&gt;
&lt;TD&gt;B_clinic&lt;/TD&gt;
&lt;TD&gt;1/11/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;123&lt;/TD&gt;
&lt;TD&gt;B_clinic&lt;/TD&gt;
&lt;TD&gt;1/11/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;123&lt;/TD&gt;
&lt;TD&gt;Other&lt;/TD&gt;
&lt;TD&gt;1/17/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;123&lt;/TD&gt;
&lt;TD&gt;B_pharmacy&lt;/TD&gt;
&lt;TD&gt;2/7/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;123&lt;/TD&gt;
&lt;TD&gt;B_clinic&lt;/TD&gt;
&lt;TD&gt;2/8/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;What the data should look like:&lt;/STRONG&gt;&lt;/P&gt;
&lt;TABLE width="275"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="87"&gt;patient_id&lt;/TD&gt;
&lt;TD width="87"&gt;med_name&lt;/TD&gt;
&lt;TD width="101"&gt;med_fill_date&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;123&lt;/TD&gt;
&lt;TD&gt;B_pharmacy&lt;/TD&gt;
&lt;TD&gt;1/9/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;123&lt;/TD&gt;
&lt;TD&gt;B_pharmacy&lt;/TD&gt;
&lt;TD&gt;2/7/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Example 2:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Original data:&lt;/STRONG&gt;&lt;/P&gt;
&lt;TABLE width="334"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="87"&gt;patient_id&lt;/TD&gt;
&lt;TD width="143"&gt;med_name&lt;/TD&gt;
&lt;TD width="104"&gt;med_fill_date&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;155&lt;/TD&gt;
&lt;TD&gt;B_pharmacy&lt;/TD&gt;
&lt;TD&gt;4/4/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;155&lt;/TD&gt;
&lt;TD&gt;B_clinic&lt;/TD&gt;
&lt;TD&gt;4/11/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;155&lt;/TD&gt;
&lt;TD&gt;B_pharmacy&lt;/TD&gt;
&lt;TD&gt;4/29/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;155&lt;/TD&gt;
&lt;TD&gt;B_pharmacy&lt;/TD&gt;
&lt;TD&gt;5/16/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;155&lt;/TD&gt;
&lt;TD&gt;B_clinic&lt;/TD&gt;
&lt;TD&gt;5/16/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;155&lt;/TD&gt;
&lt;TD&gt;B_pharmacy&lt;/TD&gt;
&lt;TD&gt;7/8/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;155&lt;/TD&gt;
&lt;TD&gt;B_pharmacy&lt;/TD&gt;
&lt;TD&gt;9/3/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;155&lt;/TD&gt;
&lt;TD&gt;B_clinic&lt;/TD&gt;
&lt;TD&gt;9/6/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What data should look like:&lt;/P&gt;
&lt;TABLE width="275"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="87"&gt;patient_id&lt;/TD&gt;
&lt;TD width="87"&gt;med_name&lt;/TD&gt;
&lt;TD width="101"&gt;med_fill_date&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;155&lt;/TD&gt;
&lt;TD&gt;B_pharmacy&lt;/TD&gt;
&lt;TD&gt;4/4/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;155&lt;/TD&gt;
&lt;TD&gt;B_pharmacy&lt;/TD&gt;
&lt;TD&gt;4/29/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;155&lt;/TD&gt;
&lt;TD&gt;B_pharmacy&lt;/TD&gt;
&lt;TD&gt;5/16/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;155&lt;/TD&gt;
&lt;TD&gt;B_pharmacy&lt;/TD&gt;
&lt;TD&gt;7/8/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;155&lt;/TD&gt;
&lt;TD&gt;B_pharmacy&lt;/TD&gt;
&lt;TD&gt;9/3/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Above data as data lines:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Original data in Example 1:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;data have(label='Prescription Data');
   length id $7;
   infile datalines  truncover;
   input patient_id:4 med_name:$10. med_fill_date:MMDDYY8. ;
Datalines;
123 B_pharmacy 1/9/19
123 B_clinic 1/11/19
123 B_clinic 1/11/19
123 B_clinic 1/17/19
123 Other 1/11/19
123 B_pharmacy 2/7/19
123 B_clinic 2/8/19
;;;;
proc sort;
 by id;
run;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Original data in Example 2:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;data have(label='Prescription Data');
   length id $7;
   infile datalines  truncover;
   input patient_id:4 med_name:$10. med_fill_date:MMDDYY8. ;
Datalines;
155 B_pharmacy 4/4/19
155 B_clinic 4/11/19
155 B_pharmacy 4/29/19
155 B_pharmacy 5/16/19
155 B_clinic 5/16/19
155 B_pharmacy 7/8/19
155 B_pharmacy 9/3/19
155 B_clinic 9/6/19
;;;;
proc sort;
 by id;
run;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 06 Aug 2022 21:03:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Medication-fill-code-conditions/m-p/827474#M326875</guid>
      <dc:creator>alaxman</dc:creator>
      <dc:date>2022-08-06T21:03:22Z</dc:date>
    </item>
    <item>
      <title>Re: Medication fill code conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Medication-fill-code-conditions/m-p/827477#M326877</link>
      <description>&lt;P&gt;Thank you for providing your sample data in the form of a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now please make sure the data step actually works.&amp;nbsp; &amp;nbsp;The code provided does not read in any of the variables correctly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But, in addition to the fact that the given DATA step generates errors, which I guess we could correct, I have these questions:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Do you actually have a &lt;EM&gt;&lt;STRONG&gt;single variable&lt;/STRONG&gt;&lt;/EM&gt; (med_name in your example) that contains &lt;EM&gt;&lt;STRONG&gt;both the medicine name and the site&lt;/STRONG&gt;&lt;/EM&gt; where the prescription is filled?&amp;nbsp; Very poor data design if so, and it makes performing the specific task you request messier that it should be.&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;What if the first prescription is followed by a second prescription for the same medication and &lt;EM&gt;&lt;STRONG&gt;filled at the same site&lt;/STRONG&gt;&lt;/EM&gt;?&amp;nbsp; Is that also subject to the 14-day minimum gap requirement, the same as having different sites?&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 06 Aug 2022 23:05:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Medication-fill-code-conditions/m-p/827477#M326877</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-08-06T23:05:06Z</dc:date>
    </item>
    <item>
      <title>Re: Medication fill code conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Medication-fill-code-conditions/m-p/827480#M326880</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See below for corrected datalines.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Example 1, Original data&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have(label='Prescription Data');
   /*length id $7;*/
   infile datalines truncover;
   input patient_id:$4. med_name:$10. med_fill_date:MMDDYY8.;
   format med_fill_date: mmddyy8.;
Datalines;
123 B_pharmacy 1/9/19
123 B_clinic 1/11/19
123 B_clinic 1/11/19
123 B_clinic 1/11/19
123 B_other 1/17/19
123 B_pharmacy 2/7/19
123 B_clinic 2/8/19
;
proc sort;
 by patient_id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;What the data should look like for Example 1:&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;TABLE width="275"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="87"&gt;patient_id&lt;/TD&gt;
&lt;TD width="87"&gt;med_name&lt;/TD&gt;
&lt;TD width="101"&gt;med_fill_date&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;123&lt;/TD&gt;
&lt;TD&gt;B_pharmacy&lt;/TD&gt;
&lt;TD&gt;1/9/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;123&lt;/TD&gt;
&lt;TD&gt;B_pharmacy&lt;/TD&gt;
&lt;TD&gt;2/7/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Example 2, Original data&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have(label='Prescription Data');
   /*length id $7;*/
   infile datalines truncover;
   input patient_id:$4. med_name:$10. med_fill_date:MMDDYY8.;
   format med_fill_date: mmddyy8.;
Datalines;
155 B_pharmacy 4/4/19
155 B_clinic 4/11/19
155 B_pharmacy 4/29/19
155 B_pharmacy 5/16/19
155 B_clinic 5/16/19
155 B_pharmacy 7/8/19
155 B_pharmacy 9/3/19
155 B_clinic 9/6/19
;
proc sort;
 by patient_id;
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;&lt;STRONG&gt;What the data should look like for Example 2:&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="275"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="87"&gt;patient_id&lt;/TD&gt;
&lt;TD width="87"&gt;med_name&lt;/TD&gt;
&lt;TD width="101"&gt;med_fill_date&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;155&lt;/TD&gt;
&lt;TD&gt;B_pharmacy&lt;/TD&gt;
&lt;TD&gt;4/4/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;155&lt;/TD&gt;
&lt;TD&gt;B_pharmacy&lt;/TD&gt;
&lt;TD&gt;4/29/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;155&lt;/TD&gt;
&lt;TD&gt;B_pharmacy&lt;/TD&gt;
&lt;TD&gt;5/16/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;155&lt;/TD&gt;
&lt;TD&gt;B_pharmacy&lt;/TD&gt;
&lt;TD&gt;7/8/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;155&lt;/TD&gt;
&lt;TD&gt;B_pharmacy&lt;/TD&gt;
&lt;TD&gt;9/3/19&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To answer your questions&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Do you actually have a&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;&lt;STRONG&gt;single variable&lt;/STRONG&gt;&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;(med_name in your example) that contains&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;&lt;STRONG&gt;both the medicine name and the site&lt;/STRONG&gt;&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;where the prescription is filled?&amp;nbsp; Very poor data design if so, and it makes performing the specific task you request messier that it should be.&lt;STRONG&gt;&lt;EM&gt; We have a single variable that has just the medication name, which we are able to determine whether it's from the pharmacy or clinic; so yes, it is encapsulated into one variable.&lt;/EM&gt;&lt;/STRONG&gt;&lt;/LI&gt;
&lt;LI&gt;What if the first prescription is followed by a second prescription for the same medication and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;&lt;STRONG&gt;filled at the same site&lt;/STRONG&gt;&lt;/EM&gt;?&amp;nbsp; Is that also subject to the 14-day minimum gap requirement, the same as having different sites? &lt;EM&gt;&lt;STRONG&gt;If it's filled at the same site,&amp;nbsp; it is not subject to the 14-day minimum gap requirement. Here is my original description of the problem:&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;A person might be prescribed “B” medication, either at a pharmacy or at a clinic (in no particular order), or another medication entirely. For cases when “B” medication is prescribed, there is a risk of double counting if the medication is prescribed at both a pharmacy and clinic within a 14-day period. Therefore, I want to delete either a pharmacy fill or clinic fill of “B” medication if they occur within 14-days of one another. In such cases, we want to keep the first row/medication fill date of either the pharmacy or clinic prescription of the same medication (and delete what we have defined as duplicates). The risk of double counting occurs only when the same medication is prescribed at both the pharmacy and clinic within this time. If we see just pharmacy prescriptions or just clinic prescriptions, this requirement does not hold.&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Sat, 06 Aug 2022 23:49:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Medication-fill-code-conditions/m-p/827480#M326880</guid>
      <dc:creator>alaxman</dc:creator>
      <dc:date>2022-08-06T23:49:59Z</dc:date>
    </item>
    <item>
      <title>Re: Medication fill code conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Medication-fill-code-conditions/m-p/827483#M326883</link>
      <description>&lt;P&gt;Thank you for fixing the DATA steps.&amp;nbsp; For the sample data your provided, this code will work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have(label='Prescription Data');
   /*length id $7;*/
   infile datalines truncover;
   input patient_id:$4. med_name:$10. med_fill_date:MMDDYY8.;
   format med_fill_date: mmddyy8.;
datalines;
155 B_pharmacy 4/4/19
155 B_clinic 4/11/19
155 B_pharmacy 4/29/19
155 B_pharmacy 5/16/19
155 B_clinic 5/16/19
155 B_pharmacy 7/8/19
155 B_pharmacy 9/3/19
155 B_clinic 9/6/19
run;

proc sort; by patient_id med_fill_date;
run;

data want (drop=_:);
  set have ;
  by patient_id med_fill_date;
  retain _last_med_fill_date .  _last_med_name '          ';
  if first.patient_id=1 or med_name=_last_med_name or med_fill_date-14&amp;gt;_last_med_fill_date;  /*Subsetting IF*/
  _last_med_fill_date=med_fill_date;
  _last_med_name=med_name;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The code above works correctly only if a patient has just one medication from multiple sites.&amp;nbsp; If a given patient has multiple meds, then you will need to take the two-component variable med_name and divide it into two variables: the actual name of the medicine, and the site the prescription was filled, as below.&amp;nbsp; I modified your sample dataset below to have a single instance of medicine A_.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have(label='Prescription Data');
   /*length id $7;*/
   infile datalines truncover;
   input patient_id:$4. med_name:$10. med_fill_date:MMDDYY8.;
   format med_fill_date: mmddyy8.;
datalines;
155 B_pharmacy 4/4/19
155 A_clinic 4/11/19
155 B_pharmacy 4/29/19
155 B_pharmacy 5/16/19
155 B_clinic 5/16/19
155 B_pharmacy 7/8/19
155 B_pharmacy 9/3/19
155 B_clinic 9/6/19
run;

data need;
  set have;
  medicine_name=scan(med_name,1,'_');
  medicine_site=scan(med_name,2,'_');
run;

proc sort;
  by patient_id medicine_name med_fill_date;
run;

data want (drop=_:);
  set need ;
  by patient_id medicine_name med_fill_date;
  retain _last_med_fill_date .  _last_medicine_site '          ';
  if first.medicine_name=1 or medicine_site=_last_medicine_site or med_fill_date-14&amp;gt;_last_med_fill_date;  /*Subsetting IF*/
  _last_med_fill_date=med_fill_date;
  _last_medicine_site=medicine_site;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Aug 2022 04:57:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Medication-fill-code-conditions/m-p/827483#M326883</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-08-07T04:57:16Z</dc:date>
    </item>
    <item>
      <title>Re: Medication fill code conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Medication-fill-code-conditions/m-p/827534#M326896</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!! Very helpful to see how you coded this. I had to make one slight tweak in the following:&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;if first.patient_id=1 or med_name=_last_med_name or med_fill_date-14&amp;gt;_last_med_fill_date;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;where the first "or" should be "and" but otherwise, it worked well.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again&lt;/P&gt;</description>
      <pubDate>Mon, 08 Aug 2022 04:56:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Medication-fill-code-conditions/m-p/827534#M326896</guid>
      <dc:creator>alaxman</dc:creator>
      <dc:date>2022-08-08T04:56:39Z</dc:date>
    </item>
  </channel>
</rss>

