<?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: Overlapping Dates- long to wide dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Overlapping-Dates-long-to-wide-dataset/m-p/404947#M98456</link>
    <description>&lt;P&gt;My algorithm is complete. Translate it to SAS code, and post that here, so we can make the necessary corrections.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 17 Oct 2017 19:09:18 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-10-17T19:09:18Z</dc:date>
    <item>
      <title>Overlapping Dates- long to wide dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overlapping-Dates-long-to-wide-dataset/m-p/404901#M98438</link>
      <description>&lt;P&gt;I have data set that is set up as follows&lt;/P&gt;
&lt;TABLE width="206"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;ID&lt;/TD&gt;
&lt;TD width="71"&gt;Start_Date&lt;/TD&gt;
&lt;TD width="71"&gt;End_Date&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;25-Jan-17&lt;/TD&gt;
&lt;TD&gt;25-Mar-17&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;1-Feb-17&lt;/TD&gt;
&lt;TD&gt;14-Feb-17&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;1-Apr-17&lt;/TD&gt;
&lt;TD&gt;30-Apr-17&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;15-Apr-17&lt;/TD&gt;
&lt;TD&gt;20-Apr-17&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;1-Nov-17&lt;/TD&gt;
&lt;TD&gt;25-Nov-17&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;16-Jun-17&lt;/TD&gt;
&lt;TD&gt;20-Jun-17&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;1-May-17&lt;/TD&gt;
&lt;TD&gt;20-May-17&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;21-May-17&lt;/TD&gt;
&lt;TD&gt;30-May-17&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;I need to go from this, to one line of data for each ID that indicates/flags whether or not the ID had overlapping dates. For example:&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 96pt;" border="0" width="128" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL style="width: 48pt;" span="2" width="64" /&gt; &lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" style="height: 15.0pt; width: 48pt;"&gt;ID&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;overlap_flag&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;3&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;4&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not sure how to do this in SAS, although I'm sure it's quite easy. Any suggestions?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Oct 2017 17:20:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overlapping-Dates-long-to-wide-dataset/m-p/404901#M98438</guid>
      <dc:creator>ntburton1</dc:creator>
      <dc:date>2017-10-17T17:20:40Z</dc:date>
    </item>
    <item>
      <title>Re: Overlapping Dates- long to wide dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overlapping-Dates-long-to-wide-dataset/m-p/404908#M98439</link>
      <description>&lt;P&gt;In a data step with by id:&lt;/P&gt;
&lt;P&gt;- retain the flag variable&lt;/P&gt;
&lt;P&gt;- retrieve the previous end_date with the lag() function.&lt;/P&gt;
&lt;P&gt;- at first.id, set the flag to zero;&lt;/P&gt;
&lt;P&gt;- if not first.id, compare the lagged end_date with the current start_date, and set flag to 1 if appropriate&lt;/P&gt;
&lt;P&gt;- at last.id, output&lt;/P&gt;
&lt;P&gt;- keep id and flag&lt;/P&gt;</description>
      <pubDate>Tue, 17 Oct 2017 17:39:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overlapping-Dates-long-to-wide-dataset/m-p/404908#M98439</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-17T17:39:12Z</dc:date>
    </item>
    <item>
      <title>Re: Overlapping Dates- long to wide dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overlapping-Dates-long-to-wide-dataset/m-p/404930#M98447</link>
      <description>&lt;P&gt;hmmm I'm not sure I understand this. I'm a pretty novice SAS user and have never used the lag function.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd have to sort on the start date first, no? Or does the lag function do this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks for your assistance!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Oct 2017 18:40:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overlapping-Dates-long-to-wide-dataset/m-p/404930#M98447</guid>
      <dc:creator>ntburton1</dc:creator>
      <dc:date>2017-10-17T18:40:56Z</dc:date>
    </item>
    <item>
      <title>Re: Overlapping Dates- long to wide dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overlapping-Dates-long-to-wide-dataset/m-p/404945#M98454</link>
      <description>&lt;P&gt;Yes you do need to sort, but your data was presented as sorted so in general we'll assume it's as shown.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you run into issues feel free to post your code and explain the issues.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We're more than happy to assist, less happy to do your work &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Oct 2017 19:07:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overlapping-Dates-long-to-wide-dataset/m-p/404945#M98454</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-17T19:07:28Z</dc:date>
    </item>
    <item>
      <title>Re: Overlapping Dates- long to wide dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overlapping-Dates-long-to-wide-dataset/m-p/404947#M98456</link>
      <description>&lt;P&gt;My algorithm is complete. Translate it to SAS code, and post that here, so we can make the necessary corrections.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Oct 2017 19:09:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overlapping-Dates-long-to-wide-dataset/m-p/404947#M98456</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-17T19:09:18Z</dc:date>
    </item>
    <item>
      <title>Re: Overlapping Dates- long to wide dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overlapping-Dates-long-to-wide-dataset/m-p/404950#M98458</link>
      <description>Your data seems to be sorted by id and start_date - should be ok. Try to write the data step using the description provided by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;. Post code and log if you receive an error message.</description>
      <pubDate>Tue, 17 Oct 2017 19:10:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overlapping-Dates-long-to-wide-dataset/m-p/404950#M98458</guid>
      <dc:creator>error_prone</dc:creator>
      <dc:date>2017-10-17T19:10:17Z</dc:date>
    </item>
    <item>
      <title>Re: Overlapping Dates- long to wide dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overlapping-Dates-long-to-wide-dataset/m-p/405207#M98547</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards expandtabs truncover;
input ID	Start_Date : date11.	End_Date : date11.;
format Start_Date End_Date : date11.;
cards;
1	25-Jan-17	25-Mar-17
1	1-Feb-17	14-Feb-17
2	1-Apr-17	30-Apr-17
2	15-Apr-17	20-Apr-17
2	1-Nov-17	25-Nov-17
3	16-Jun-17	20-Jun-17
4	1-May-17	20-May-17
4	21-May-17	30-May-17
;
run;
data temp;
 set have;
 by id;
 flag=(Start_Date&amp;lt;lag(End_Date));
 if first.id then flag=0;
run;
proc sql;
select id,max(flag) as flag
 from temp
  group by id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Oct 2017 13:49:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overlapping-Dates-long-to-wide-dataset/m-p/405207#M98547</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-10-18T13:49:32Z</dc:date>
    </item>
  </channel>
</rss>

