<?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: Flag a Member_ID with different Drug within 45 days of last Fill in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Flag-a-Member-ID-with-different-Drug-within-45-days-of-last-Fill/m-p/840929#M332493</link>
    <description>&lt;P&gt;What is wrong with the code you show?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please provide example data as &lt;FONT color="#FF0000"&gt;working&lt;/FONT&gt; SAS data step code (&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;Instructions&lt;/A&gt;)&lt;/P&gt;</description>
    <pubDate>Wed, 26 Oct 2022 14:57:22 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-10-26T14:57:22Z</dc:date>
    <item>
      <title>Flag a Member_ID with different Drug within 45 days of last Fill</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-a-Member-ID-with-different-Drug-within-45-days-of-last-Fill/m-p/840926#M332491</link>
      <description>&lt;P&gt;Howdy all!&amp;nbsp; I have a list of claims and I am trying to flag those claims where a member's next claim was within 45 days and for a different drug.&amp;nbsp; Essentially, the ask is to look to see if a member has filled multiple drugs within 45 days.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the code I have built so far.&amp;nbsp; Have commented out some of what I was testing:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dummy sample (what is in bold needs to be flagged):&lt;/P&gt;
&lt;TABLE width="424"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="113"&gt;SRC_MEMBER_ID&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;TD&gt;15&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;STRONG&gt;22222222&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;19-Apr-22&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;DRUGD&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;MIGRAINE&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;25&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=work.tbl_dup_conseq_01b;&lt;/P&gt;
&lt;P&gt;by src_member_id fill_dt drug_nm drug_class;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;data work.tbl_dup_conseq_02;&lt;/P&gt;
&lt;P&gt;set work.tbl_dup_conseq_01b;&lt;/P&gt;
&lt;P&gt;/*by src_member_id drug_nm drug_class;*/&lt;/P&gt;
&lt;P&gt;duration = intck("day", lag(fill_dt), fill_dt);&lt;BR /&gt;do until(last.drug_nm);&lt;BR /&gt;if first.drug_nm and duration &amp;lt;= 45 then flag = "Y";&lt;BR /&gt;end;&lt;BR /&gt;/*drop duration*/;&lt;/P&gt;
&lt;P&gt;run;&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>Wed, 26 Oct 2022 14:57:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-a-Member-ID-with-different-Drug-within-45-days-of-last-Fill/m-p/840926#M332491</guid>
      <dc:creator>PhatRam33</dc:creator>
      <dc:date>2022-10-26T14:57:16Z</dc:date>
    </item>
    <item>
      <title>Re: Flag a Member_ID with different Drug within 45 days of last Fill</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-a-Member-ID-with-different-Drug-within-45-days-of-last-Fill/m-p/840929#M332493</link>
      <description>&lt;P&gt;What is wrong with the code you show?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please provide example data as &lt;FONT color="#FF0000"&gt;working&lt;/FONT&gt; SAS data step code (&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;Instructions&lt;/A&gt;)&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2022 14:57:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-a-Member-ID-with-different-Drug-within-45-days-of-last-Fill/m-p/840929#M332493</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-10-26T14:57:22Z</dc:date>
    </item>
    <item>
      <title>Re: Flag a Member_ID with different Drug within 45 days of last Fill</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-a-Member-ID-with-different-Drug-within-45-days-of-last-Fill/m-p/840931#M332494</link>
      <description>&lt;P&gt;I tried to run my code however, looks like it is in an infinite loop. Keeps running without completion.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2022 14:58:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-a-Member-ID-with-different-Drug-within-45-days-of-last-Fill/m-p/840931#M332494</guid>
      <dc:creator>PhatRam33</dc:creator>
      <dc:date>2022-10-26T14:58:54Z</dc:date>
    </item>
    <item>
      <title>Re: Flag a Member_ID with different Drug within 45 days of last Fill</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-a-Member-ID-with-different-Drug-within-45-days-of-last-Fill/m-p/840934#M332495</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do until(last.id);
if first.drug_nm and duration &amp;lt;= 45 then flag = "Y";
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since nothing in the loop can change the value of last.id, this loop will never terminate when there is more than one observation for a drug_nm group. You must have the SET statement&amp;nbsp;&lt;U&gt;in&lt;/U&gt; such a DO loop for it to work.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2022 15:13:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-a-Member-ID-with-different-Drug-within-45-days-of-last-Fill/m-p/840934#M332495</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-10-26T15:13:55Z</dc:date>
    </item>
    <item>
      <title>Re: Flag a Member_ID with different Drug within 45 days of last Fill</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-a-Member-ID-with-different-Drug-within-45-days-of-last-Fill/m-p/840935#M332496</link>
      <description>&lt;P&gt;Yes thats what happens when you comment out the BY statement, and then try to look for a value (last.drug_nm) that is produced via the BY statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please in the future, when you know the symptoms of a problem, please don't withhold that information from us.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2022 15:16:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-a-Member-ID-with-different-Drug-within-45-days-of-last-Fill/m-p/840935#M332496</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-10-26T15:16:18Z</dc:date>
    </item>
    <item>
      <title>Re: Flag a Member_ID with different Drug within 45 days of last Fill</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-a-Member-ID-with-different-Drug-within-45-days-of-last-Fill/m-p/840938#M332497</link>
      <description>&lt;P&gt;The apparent infinite loop is in the code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do until(last.drug_nm);
  if first.drug_nm and duration &amp;lt;= 45 then flag = "Y";
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The loop will not stop until the last obs for a given drug has been encountered.&amp;nbsp; But the loop does not actually proceed through the data, so the last.drug_nm condition will never occur.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now this diagnosis is appropriate when the BY statement is uncommented.&amp;nbsp; As it is (with the BY commented out), prior to you terminating the data step, you should get NOTEs on your log like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: Variable last.drug_nm is uninitialized.
NOTE: Variable first.drug_nm is uninitialized.
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can do without the loop entirely, with (untested code):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.tbl_dup_conseq_02;
  set work.tbl_dup_conseq_01b;
  by src_member_id drug_nm drug_class;

  duration = intck("day", lag(fill_dt), fill_dt);
  if first.drug_nm=1 and first.src_member_id=0 and duration&amp;lt;=45 then flag = "Y";
  drop duration;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Editted addition:&amp;nbsp; The BY statement should match the BY statement in the proc sort, i.e.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  by src_member_id fill_dt drug_nm drug_class;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Oct 2022 15:23:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-a-Member-ID-with-different-Drug-within-45-days-of-last-Fill/m-p/840938#M332497</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-10-26T15:23:01Z</dc:date>
    </item>
    <item>
      <title>Re: Flag a Member_ID with different Drug within 45 days of last Fill</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-a-Member-ID-with-different-Drug-within-45-days-of-last-Fill/m-p/840952#M332498</link>
      <description>&lt;P&gt;Almost there.&amp;nbsp; I tried the code below and it flags each line if duration is &amp;lt;= 45 regardless if member filled for a different drug or not.&amp;nbsp; Trying to get it to flag where all the conditions are true.&amp;nbsp; Same member, different drug, and &amp;lt;=45 days if that makes sense. Appreciate all the help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data work.tbl_dup_conseq_02;&lt;BR /&gt;set work.tbl_dup_conseq_01b;&lt;BR /&gt;by src_member_id fill_dt drug_nm drug_class;&lt;/P&gt;
&lt;P&gt;duration = intck("day", lag(fill_dt), fill_dt);&lt;BR /&gt;if first.drug_nm=1 and first.src_member_id=0 and duration&amp;lt;=45 then flag = "Y";&lt;BR /&gt;/*drop duration;*/&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2022 16:16:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-a-Member-ID-with-different-Drug-within-45-days-of-last-Fill/m-p/840952#M332498</guid>
      <dc:creator>PhatRam33</dc:creator>
      <dc:date>2022-10-26T16:16:43Z</dc:date>
    </item>
    <item>
      <title>Re: Flag a Member_ID with different Drug within 45 days of last Fill</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-a-Member-ID-with-different-Drug-within-45-days-of-last-Fill/m-p/840972#M332501</link>
      <description>&lt;P&gt;Can you show us a portion of the input data, and the output from this program?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2022 16:57:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-a-Member-ID-with-different-Drug-within-45-days-of-last-Fill/m-p/840972#M332501</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-10-26T16:57:41Z</dc:date>
    </item>
    <item>
      <title>Re: Flag a Member_ID with different Drug within 45 days of last Fill</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-a-Member-ID-with-different-Drug-within-45-days-of-last-Fill/m-p/840980#M332502</link>
      <description>To add to my reply, I got the code to work by using the lag function for the drug_nm as well and did the trick to satisfy the required criteria.&lt;BR /&gt;&lt;BR /&gt;data work.tbl_dup_conseq_02;&lt;BR /&gt;  set work.tbl_dup_conseq_01b;&lt;BR /&gt;  by src_member_id fill_dt drug_nm drug_class;&lt;BR /&gt;&lt;BR /&gt;  duration = intck("day", lag(fill_dt), fill_dt);&lt;BR /&gt;  drug_nm2 = lag(drug_nm);&lt;BR /&gt;  if drug_nm ^= drug_nm2 and first.src_member_id=0 and duration &amp;lt;= 45 and duration &amp;gt;=1 then flag = 'Y';&lt;BR /&gt;run;</description>
      <pubDate>Wed, 26 Oct 2022 17:46:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-a-Member-ID-with-different-Drug-within-45-days-of-last-Fill/m-p/840980#M332502</guid>
      <dc:creator>PhatRam33</dc:creator>
      <dc:date>2022-10-26T17:46:14Z</dc:date>
    </item>
  </channel>
</rss>

