<?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: Summing consecutive events by patient id and date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Summing-consecutive-events-by-patient-id-and-date/m-p/587561#M167841</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/289200"&gt;@Allegra&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I meant consecutive days. Taking Patient 3 as an example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1st prescription: 31AUG2013: NO FLAG&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2nd prescription to 5th prescription: (NDC: 591261205) &lt;STRONG&gt;09DEC2013 TO 12DEC2013 &lt;/STRONG&gt;ie no break-in days which equates to 4 days.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;6th prescription to 8th:&amp;nbsp; (NDC: 591261205) &lt;STRONG&gt;19JUNE2014 TO 21STJUNE2014 &lt;/STRONG&gt;ie no break in days which equates to 3 days&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Question: why is duration not&amp;nbsp; 7days because of same NDC?&lt;/P&gt;
&lt;P&gt;Explanation: 5th prescription was taken &lt;STRONG&gt;12DEC2013&lt;/STRONG&gt; while 6th prescription was on&amp;nbsp;&lt;STRONG&gt;19JUNE2014 &lt;/STRONG&gt;(a gap of almost 6 months), thus I want to keep them separate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If patient 3, however, had 6th to 8th prescription from 13DEC2013 TO 15DEC2013 for that same NDC, Duration would have been added to 7days.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry, English is not my first language, so I am trying to explain as best as I can.&lt;/P&gt;
&lt;P&gt;Again, thank you for your time:)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
	by id ndc date;
run;
data want;
	set have;
	by id ndc;
        prev_date=lag(date);
	if first.ndc or date-prev_date&amp;gt;1 then duration=0;
	duration+flag;
	if duration=0 or last.ndc or date-prev_date&amp;gt;1 then output;
        drop prev_date;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 10 Sep 2019 15:29:56 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2019-09-10T15:29:56Z</dc:date>
    <item>
      <title>Summing consecutive events by patient id and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-consecutive-events-by-patient-id-and-date/m-p/587349#M167757</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please, how do I&lt;/P&gt;&lt;P&gt;First step: sum up consecutive flag variable by id, date, and NDC code?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Second step: Collapse by id and flag. For patients that have both '0' and '1' flag, I want to keep only their '1' and then sum up all consecutive '1's as a variable called duration.&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;&lt;PRE&gt;&amp;nbsp;&lt;/PRE&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Apr 2020 23:20:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-consecutive-events-by-patient-id-and-date/m-p/587349#M167757</guid>
      <dc:creator>Allegra</dc:creator>
      <dc:date>2020-04-01T23:20:33Z</dc:date>
    </item>
    <item>
      <title>Re: Summing consecutive events by patient id and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-consecutive-events-by-patient-id-and-date/m-p/587352#M167758</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
	by id ndc date;
run;
data want;
	set have;
	by id ndc;
	if first.ndc then duration=0;
	duration+flag;
	if duration=0 or last.ndc then output;
run;
proc summary data=want nway;
    class id flag;
	var duration;
	output out=want2 sum=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Want2 may have a few unwanted records with FLAG=0, but you can get rid of those.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2019 20:13:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-consecutive-events-by-patient-id-and-date/m-p/587352#M167758</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-09-09T20:13:06Z</dc:date>
    </item>
    <item>
      <title>Re: Summing consecutive events by patient id and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-consecutive-events-by-patient-id-and-date/m-p/587359#M167759</link>
      <description>&lt;P&gt;Sir&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; Is this OPs expected sample1 output correct?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;591261205&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;4&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;591261205&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;STRONG&gt;3&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/289200"&gt;@Allegra&lt;/a&gt;&amp;nbsp; &amp;nbsp;Can you clarify plz&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2019 20:35:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-consecutive-events-by-patient-id-and-date/m-p/587359#M167759</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-09-09T20:35:18Z</dc:date>
    </item>
    <item>
      <title>Re: Summing consecutive events by patient id and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-consecutive-events-by-patient-id-and-date/m-p/587365#M167761</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;yes sample 1 expected output is correct because the dates are not consecutive even though the NDC is the same. ie there's a break from 12dec2013 to 19june2014.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;code collapses those two dates, so it is not correct for that ID&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2019 21:12:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-consecutive-events-by-patient-id-and-date/m-p/587365#M167761</guid>
      <dc:creator>Allegra</dc:creator>
      <dc:date>2019-09-09T21:12:50Z</dc:date>
    </item>
    <item>
      <title>Re: Summing consecutive events by patient id and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-consecutive-events-by-patient-id-and-date/m-p/587366#M167762</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/289200"&gt;@Allegra&lt;/a&gt;&amp;nbsp; Thank you. I appreciate it&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2019 21:10:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-consecutive-events-by-patient-id-and-date/m-p/587366#M167762</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-09-09T21:10:39Z</dc:date>
    </item>
    <item>
      <title>Re: Summing consecutive events by patient id and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-consecutive-events-by-patient-id-and-date/m-p/587367#M167763</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;Thank you for your swift response. For ID, it summed up the non-consecutive events with same ndc into 5 is there a way to make that a distinction into 3 &amp;amp; 2?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your help&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2019 21:18:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-consecutive-events-by-patient-id-and-date/m-p/587367#M167763</guid>
      <dc:creator>Allegra</dc:creator>
      <dc:date>2019-09-09T21:18:40Z</dc:date>
    </item>
    <item>
      <title>Re: Summing consecutive events by patient id and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-consecutive-events-by-patient-id-and-date/m-p/587385#M167769</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/289200"&gt;@Allegra&lt;/a&gt;&amp;nbsp;This original sample is still confusing&lt;/P&gt;
&lt;PRE&gt;3 09DEC2013 591261205 1
3 10DEC2013 591261205 1
3 11DEC2013 591261205 1
3 12DEC2013 591261205 1
3 19JUN2014 591320205 1&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;591261205 4 makes sense&amp;nbsp;&lt;/P&gt;
&lt;P&gt;591261205 3&lt;/P&gt;
&lt;P&gt;however on 19 the NDC is&amp;nbsp;591320205 which different, so i'm wondering where you got the 3 from&lt;/P&gt;</description>
      <pubDate>Tue, 10 Sep 2019 00:19:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-consecutive-events-by-patient-id-and-date/m-p/587385#M167769</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-09-10T00:19:21Z</dc:date>
    </item>
    <item>
      <title>Re: Summing consecutive events by patient id and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-consecutive-events-by-patient-id-and-date/m-p/587477#M167805</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/289200"&gt;@Allegra&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please, how do I&lt;/P&gt;
&lt;P&gt;First step: sum up consecutive flag variable by id, date, and NDC code?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What do you mean by "consecutive"? Consecutive days, or consecutive records in the file, or something else?&lt;/P&gt;</description>
      <pubDate>Tue, 10 Sep 2019 12:01:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-consecutive-events-by-patient-id-and-date/m-p/587477#M167805</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-09-10T12:01:12Z</dc:date>
    </item>
    <item>
      <title>Re: Summing consecutive events by patient id and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-consecutive-events-by-patient-id-and-date/m-p/587548#M167836</link>
      <description>&lt;P&gt;The '3' is not added to the previous one even though they have the same NDC code because of the date variable. The patient had a prescription&amp;nbsp; in 12DEC2013 and the next one was on 19JUN2014 THROUGH 21JUNE2014 (3 DAYS). Because there is almost a 6months lapse between Dec and June, the dates are not consecutive.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Sep 2019 15:10:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-consecutive-events-by-patient-id-and-date/m-p/587548#M167836</guid>
      <dc:creator>Allegra</dc:creator>
      <dc:date>2019-09-10T15:10:54Z</dc:date>
    </item>
    <item>
      <title>Re: Summing consecutive events by patient id and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-consecutive-events-by-patient-id-and-date/m-p/587557#M167839</link>
      <description>&lt;P&gt;I meant consecutive days. Taking Patient 3 as an example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1st prescription: 31AUG2013: NO FLAG&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2nd prescription to 5th prescription: (NDC: 591261205) &lt;STRONG&gt;09DEC2013 TO 12DEC2013 &lt;/STRONG&gt;ie no break-in days which equates to 4 days.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;6th prescription to 8th:&amp;nbsp; (NDC: 591261205) &lt;STRONG&gt;19JUNE2014 TO 21STJUNE2014 &lt;/STRONG&gt;ie no break in days which equates to 3 days&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Question: why is duration not&amp;nbsp; 7days because of same NDC?&lt;/P&gt;&lt;P&gt;Explanation: 5th prescription was taken &lt;STRONG&gt;12DEC2013&lt;/STRONG&gt; while 6th prescription was on&amp;nbsp;&lt;STRONG&gt;19JUNE2014 &lt;/STRONG&gt;(a gap of almost 6 months), thus I want to keep them separate.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If patient 3, however, had 6th to 8th prescription from 13DEC2013 TO 15DEC2013 for that same NDC, Duration would have been added to 7days.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry, English is not my first language, so I am trying to explain as best as I can.&lt;/P&gt;&lt;P&gt;Again, thank you for your time:)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Sep 2019 15:24:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-consecutive-events-by-patient-id-and-date/m-p/587557#M167839</guid>
      <dc:creator>Allegra</dc:creator>
      <dc:date>2019-09-10T15:24:53Z</dc:date>
    </item>
    <item>
      <title>Re: Summing consecutive events by patient id and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-consecutive-events-by-patient-id-and-date/m-p/587561#M167841</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/289200"&gt;@Allegra&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I meant consecutive days. Taking Patient 3 as an example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1st prescription: 31AUG2013: NO FLAG&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2nd prescription to 5th prescription: (NDC: 591261205) &lt;STRONG&gt;09DEC2013 TO 12DEC2013 &lt;/STRONG&gt;ie no break-in days which equates to 4 days.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;6th prescription to 8th:&amp;nbsp; (NDC: 591261205) &lt;STRONG&gt;19JUNE2014 TO 21STJUNE2014 &lt;/STRONG&gt;ie no break in days which equates to 3 days&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Question: why is duration not&amp;nbsp; 7days because of same NDC?&lt;/P&gt;
&lt;P&gt;Explanation: 5th prescription was taken &lt;STRONG&gt;12DEC2013&lt;/STRONG&gt; while 6th prescription was on&amp;nbsp;&lt;STRONG&gt;19JUNE2014 &lt;/STRONG&gt;(a gap of almost 6 months), thus I want to keep them separate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If patient 3, however, had 6th to 8th prescription from 13DEC2013 TO 15DEC2013 for that same NDC, Duration would have been added to 7days.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry, English is not my first language, so I am trying to explain as best as I can.&lt;/P&gt;
&lt;P&gt;Again, thank you for your time:)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
	by id ndc date;
run;
data want;
	set have;
	by id ndc;
        prev_date=lag(date);
	if first.ndc or date-prev_date&amp;gt;1 then duration=0;
	duration+flag;
	if duration=0 or last.ndc or date-prev_date&amp;gt;1 then output;
        drop prev_date;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Sep 2019 15:29:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-consecutive-events-by-patient-id-and-date/m-p/587561#M167841</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-09-10T15:29:56Z</dc:date>
    </item>
  </channel>
</rss>

