<?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: dates within the range by subjects in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/dates-within-the-range-by-subjects/m-p/341205#M78066</link>
    <description>&lt;P&gt;Post test data in&amp;nbsp;&lt;STRONG&gt;the form of a datastep.&lt;/STRONG&gt; &amp;nbsp;As such I will just give some theory answers here:&lt;/P&gt;
&lt;P&gt;To get duplicates, you can use:&lt;/P&gt;
&lt;PRE&gt;proc sort ... nodupkey dupout=duplicates; 
  by ...; 
run;&lt;/PRE&gt;
&lt;P&gt;The by group identifies the duplciates.&lt;/P&gt;
&lt;P&gt;As for your other question on outputting several of the rows, sorry, I don't get the logic please calrify.&lt;/P&gt;</description>
    <pubDate>Wed, 15 Mar 2017 14:39:48 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-03-15T14:39:48Z</dc:date>
    <item>
      <title>dates within the range by subjects</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-within-the-range-by-subjects/m-p/341194#M78061</link>
      <description>&lt;P&gt;output where there are dates&amp;nbsp;interruption records with overlapping or duplicate dates.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;subject having multi records should be within the range from starting and end date&lt;BR /&gt;for example for ID1: we need after 2nd row. becoz end date is greater than starting date after that&lt;BR /&gt;records are within the range of dates. and also need to o/p dulicates.&lt;/P&gt;&lt;P&gt;data set like below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Subject&lt;/TD&gt;&lt;TD&gt;Row&lt;/TD&gt;&lt;TD&gt;stdt&lt;/TD&gt;&lt;TD&gt;edt&lt;/TD&gt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;/TD&gt;&lt;TD&gt;3/16/2017&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;output&lt;/TD&gt;&lt;TD&gt;Duplicates&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ID5&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;3/16/2017&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;output&lt;/TD&gt;&lt;TD&gt;Duplicates&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ID6&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;3/16/2017&lt;/TD&gt;&lt;TD&gt;3/28/2017&lt;/TD&gt;&lt;TD&gt;output&lt;/TD&gt;&lt;TD&gt;Duplicates&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ID6&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;3/16/2017&lt;/TD&gt;&lt;TD&gt;3/28/2017&lt;/TD&gt;&lt;TD&gt;output&lt;/TD&gt;&lt;TD&gt;Duplicates&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/13568i31AA32EC1A903F96/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="Capture1.PNG" title="Capture1.PNG" /&gt;</description>
      <pubDate>Wed, 15 Mar 2017 14:03:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-within-the-range-by-subjects/m-p/341194#M78061</guid>
      <dc:creator>SrikanthY</dc:creator>
      <dc:date>2017-03-15T14:03:41Z</dc:date>
    </item>
    <item>
      <title>Re: dates within the range by subjects</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-within-the-range-by-subjects/m-p/341204#M78065</link>
      <description>&lt;P&gt;I am not quite sure I understand your logic involving dates.&lt;/P&gt;
&lt;P&gt;Why is this one in the output:&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;ID4&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;3/16/2017&lt;/TD&gt;
&lt;TD&gt;3/28/2017&lt;/TD&gt;
&lt;TD&gt;output&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;but this one is not?&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;ID3&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;3/6/2017&lt;/TD&gt;
&lt;TD&gt;3/15/2017&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;If there is a specific value of edt to compare you need to tell us what it may be.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2017 14:39:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-within-the-range-by-subjects/m-p/341204#M78065</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-15T14:39:16Z</dc:date>
    </item>
    <item>
      <title>Re: dates within the range by subjects</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-within-the-range-by-subjects/m-p/341205#M78066</link>
      <description>&lt;P&gt;Post test data in&amp;nbsp;&lt;STRONG&gt;the form of a datastep.&lt;/STRONG&gt; &amp;nbsp;As such I will just give some theory answers here:&lt;/P&gt;
&lt;P&gt;To get duplicates, you can use:&lt;/P&gt;
&lt;PRE&gt;proc sort ... nodupkey dupout=duplicates; 
  by ...; 
run;&lt;/PRE&gt;
&lt;P&gt;The by group identifies the duplciates.&lt;/P&gt;
&lt;P&gt;As for your other question on outputting several of the rows, sorry, I don't get the logic please calrify.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2017 14:39:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-within-the-range-by-subjects/m-p/341205#M78066</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-03-15T14:39:48Z</dc:date>
    </item>
    <item>
      <title>Re: dates within the range by subjects</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-within-the-range-by-subjects/m-p/341216#M78069</link>
      <description>for ID3 starting date on 6th end date 15th.. after end date (15th) then&lt;BR /&gt;again starting date 16th. that between that there is no other dates&lt;BR /&gt;falling. so we dont want that records.&lt;BR /&gt;&lt;BR /&gt;for ID4 starting date is 16th and end date is 30th. there are many dates&lt;BR /&gt;falling b/w those dates.&lt;BR /&gt;&lt;BR /&gt;once the starting date is first and end date is last than starting date&lt;BR /&gt;should be greater that last end date.&lt;BR /&gt;&lt;BR /&gt;say for example drug a given for subject x on 6th and end on 10th. and&lt;BR /&gt;again started on 12th and end on 18th.&lt;BR /&gt;if any records coming b/w on 14th and end on 16th. that means duplicate&lt;BR /&gt;records.. once started on 12 th and ending on 18th. wy again 14th and 16th&lt;BR /&gt;day records.&lt;BR /&gt;&lt;BR /&gt;##- Please type your reply above this line. Simple formatting, no&lt;BR /&gt;attachments. -##</description>
      <pubDate>Wed, 15 Mar 2017 14:52:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-within-the-range-by-subjects/m-p/341216#M78069</guid>
      <dc:creator>SrikanthY</dc:creator>
      <dc:date>2017-03-15T14:52:38Z</dc:date>
    </item>
    <item>
      <title>Re: dates within the range by subjects</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-within-the-range-by-subjects/m-p/341258#M78083</link>
      <description>&lt;P&gt;I think this is what you are describing:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Form a date range using the min STDT and max EDT from a series of consecutive records.&amp;nbsp;&amp;nbsp;Every record in the group must have at least a single day intersection with at least one other record in the group.&amp;nbsp;&amp;nbsp;Records that are merely adjacent to a range are not included.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is that your intention?&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, 15 Mar 2017 16:54:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-within-the-range-by-subjects/m-p/341258#M78083</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-03-15T16:54:05Z</dc:date>
    </item>
    <item>
      <title>Re: dates within the range by subjects</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-within-the-range-by-subjects/m-p/341301#M78091</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I think this is what you are describing:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Form a date range using the min STDT and max EDT from a series of consecutive records.&amp;nbsp;&amp;nbsp;Every record in the group must have at least a single day intersection with at least one other record in the group.&amp;nbsp;&amp;nbsp;Records that are merely adjacent to a range are not included.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is that your intention?&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;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If my assumptions above are correct, then this program will provide what you need:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See revision comments below - (this program is incomplete).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;

  do N=1 by 1 until (last.subject or min(period_edt,nxt_stdt));
    set have;
    by subject;
    merge have  have (firstobs=2 keep=stdt rename=(stdt=nxt_stdt));
	period_edt=max(period_edt,edt);
	if first.subject then period_edt=edt;

  end;
  if N&amp;gt;1 then OPx='output';
  do I=1 to N; 
    set have;
	by subject stdt edt notsorted;
	if first.edt=0 or last.edt=0 then comment='Duplicates'
	else comment='N';
    output;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Notes:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The program has two DO loops.&amp;nbsp; The first loops reads in a set of records (for a single "period"), and the 2nd re-reads the same set of records.&lt;/LI&gt;
&lt;LI&gt;The first DO N=1 by 1 until ... does the following
&lt;OL&gt;
&lt;LI&gt;If the record in hand overlaps with the prior cumulative period, then update the period_edt.&lt;/LI&gt;
&lt;LI&gt;The loop stops at the end of a subject, or if the current period_edt falls short of the stdt of the next record&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;LI&gt;Then if N is &amp;gt;1 set "output" on&lt;/LI&gt;
&lt;LI&gt;The second DO rereads the same records.&lt;/LI&gt;
&lt;OL&gt;
&lt;LI&gt;It has a "by subject stdt edt notsorted" to help detect when there are duplicate records&lt;/LI&gt;
&lt;/OL&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;REvision:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Besides a typo in the above program, I didn't program for a subsequent record overlapping the &lt;EM&gt;&lt;STRONG&gt;lower&lt;/STRONG&gt;&lt;/EM&gt; end of the current period.&amp;nbsp; Also a minor fix to account for missing edt:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;

  do N=1 by 1 until (last.subject or period_edt&amp;lt;nxt_stdt or period_stdt&amp;gt;coalesce(nxt_edt,nxt_stdt) );
    set have;
    by subject;
    merge have  have (firstobs=2 keep=stdt edt rename=(stdt=nxt_stdt edt=nxt_edt));
    period_edt=max(period_edt,edt,stdt);
    period_stdt=min(period_stdt,stdt);
    if first.subject then do;
      period_edt=edt;
      period_stdt=stdt;
    end;
  end;

  if N&amp;gt;1 then OPx='output';

  do I=1 to N; 
    set have;
      by subject stdt edt notsorted;
      if first.edt=0 or last.edt=0 then comment='Duplicates';
      else comment=' ';
    output;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Mar 2017 21:28:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-within-the-range-by-subjects/m-p/341301#M78091</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-03-15T21:28:44Z</dc:date>
    </item>
  </channel>
</rss>

