<?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: Extract concurrence dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extract-concurrence-dates/m-p/486350#M126533</link>
    <description>&lt;P&gt;Sure.Assuming your table has been sorted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ae;
input id aes$ stdt:date9. aeendt:date9.;
format stdt:date8. aeendt:date8.;
cards;
1 x 20nov2016 30nov2017
1 x 28nov2016 03dec2017
1 x 04dec2017 08dec2018
1 y 04nov2016 20nov2017
2 z 01jan2016 08jan2017
2 z 30dec2015 10jan2017
2 z 01nov2017 03nov2017
3 x 01jan2016 10jan2016
3 x 01feb2016 28feb2016
3 y 01feb2016 28jan2016
4 x 01jan2016 08jan2016
4 x 01jan2016 08jan2016
4 x 02jan2016 08jan2016
;
run;
data want;
 if _n_=1 then do;
   declare hash h();
   declare hiter hi('h');
   h.definekey('date');
   h.definedata('date','n');
   h.definedone();
   
   declare hash k();
   k.definekey('date');
   k.definedone();
 end;
do until(last.aes);
 set ae;
 by id aes;
 do date=stdt to aeendt;
  if h.find()=0 then do;n=n+1;h.replace();end;
    else do;n=1;h.add();end;
 end;
end;

do while(hi.next()=0);
  if n&amp;gt;1 then k.add();
end;

do until(last.aes);
 set ae;
 by id aes;
 do date=stdt to aeendt;
    if k.check()=0 then do;output;leave;end;
 end;
end;

h.clear();k.clear();
drop n date;
run;

proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 13 Aug 2018 14:03:45 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2018-08-13T14:03:45Z</dc:date>
    <item>
      <title>Extract concurrence dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-concurrence-dates/m-p/485688#M126222</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;I have been working on a data to extract concurrence dates (dates that overlap&amp;nbsp;on other), I have cracked a code and go desired output, but I have been trying for even simpler code that reduces process time, so I taught of posting here so that I can gain some knowledge.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Note: overlap dates have to be checked for groups within ID and aes&amp;nbsp;vars.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Heres My data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ae;
input id aes$ stdt:date9. aeendt:date9.;
format stdt:date8. aeendt:date8.;
cards;
1 x 20nov2016 30nov2017
1 x 28nov2016 03dec2017
1 x 04dec2017 08dec2018
1 y 04nov2016 20nov2017
2 z 01jan2016 08jan2017
2 z 30dec2015 10jan2017
2 z 01nov2017 03nov2017
3 x 01jan2016 10jan2016
3 x 01feb2016 28feb2016
3 y 01feb2016 28jan2016
4 x 01jan2016 08jan2016
4 x 01jan2016 08jan2016
4 x 02jan2016 08jan2016
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;required output is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; id aes stdt aeendt 
 1 x 20NOV16 30NOV17 
 1 x 28NOV16 03DEC17 
 2 z 30DEC15 10JAN17 
 2 z 01JAN16 08JAN17 
 4 x 01JAN16 08JAN16 
 4 x 01JAN16 08JAN16 
 4 x 02JAN16 08JAN16 

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Here's my code to reach&amp;nbsp;above output:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data = ae;
by id aes stdt;
run;
data xyz1;
set ae ;
by id aes;
x = _n_ - 1;
n = _n_;
if (first.aes = 0  &amp;amp; stdt &amp;lt; lag(aeendt)) | (first.aes=0 &amp;amp; lag(aeendt) eq .) then do;
	set ae point = x;
	z = x;
	output;
	set ae point = n;
	z = n;
	output;
end;
proc sort nodupkey ;
by z;
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I have been anticipating for a simpler and efficient code that can reduce process time, looking forward for any responses. Just taught to post here so that I can gain some knowledge.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Manoj&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Aug 2018 09:24:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-concurrence-dates/m-p/485688#M126222</guid>
      <dc:creator>s_manoj</dc:creator>
      <dc:date>2018-08-10T09:24:14Z</dc:date>
    </item>
    <item>
      <title>Re: Extract concurrence dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-concurrence-dates/m-p/485762#M126250</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ae;
input id aes$ stdt:date9. aeendt:date9.;
format stdt:date8. aeendt:date8.;
cards;
1 x 20nov2016 30nov2017
1 x 28nov2016 03dec2017
1 x 04dec2017 08dec2018
1 y 04nov2016 20nov2017
2 z 01jan2016 08jan2017
2 z 30dec2015 10jan2017
2 z 01nov2017 03nov2017
3 x 01jan2016 10jan2016
3 x 01feb2016 28feb2016
3 y 01feb2016 28jan2016
4 x 01jan2016 08jan2016
4 x 01jan2016 08jan2016
4 x 02jan2016 08jan2016
;
run;
data ae;
 set ae;
  n+1;
run;
data temp;
 set ae;
 do date=stdt to aeendt;
   output;
 end;
 format date date9.;
 drop stdt aeendt;
run;
proc sort data=temp out=temp1;
by id aes date;
run;
proc sql;
create table temp2 as
 select distinct n
  from temp1
   group by id,aes,date
    having count(*) &amp;gt; 1;

create table want as
 select *
  from ae
   where n in (select n from temp2)
    order by n;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Aug 2018 13:36:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-concurrence-dates/m-p/485762#M126250</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-08-10T13:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: Extract concurrence dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-concurrence-dates/m-p/485775#M126253</link>
      <description>Thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&lt;BR /&gt;will try this code.</description>
      <pubDate>Fri, 10 Aug 2018 14:16:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-concurrence-dates/m-p/485775#M126253</guid>
      <dc:creator>s_manoj</dc:creator>
      <dc:date>2018-08-10T14:16:02Z</dc:date>
    </item>
    <item>
      <title>Re: Extract concurrence dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-concurrence-dates/m-p/486149#M126432</link>
      <description>Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&lt;BR /&gt;checked your code and its working, Thank you for that.&lt;BR /&gt;in data step code you have been expanding no of observations,&lt;BR /&gt;this step might take lots of time while working on large datasets like &amp;gt; one million record/ 1gb of data...&lt;BR /&gt;I am looking for a code which can save execution time, can you help me with that.&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;Manoj</description>
      <pubDate>Sun, 12 Aug 2018 12:46:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-concurrence-dates/m-p/486149#M126432</guid>
      <dc:creator>s_manoj</dc:creator>
      <dc:date>2018-08-12T12:46:56Z</dc:date>
    </item>
    <item>
      <title>Re: Extract concurrence dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-concurrence-dates/m-p/486350#M126533</link>
      <description>&lt;P&gt;Sure.Assuming your table has been sorted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ae;
input id aes$ stdt:date9. aeendt:date9.;
format stdt:date8. aeendt:date8.;
cards;
1 x 20nov2016 30nov2017
1 x 28nov2016 03dec2017
1 x 04dec2017 08dec2018
1 y 04nov2016 20nov2017
2 z 01jan2016 08jan2017
2 z 30dec2015 10jan2017
2 z 01nov2017 03nov2017
3 x 01jan2016 10jan2016
3 x 01feb2016 28feb2016
3 y 01feb2016 28jan2016
4 x 01jan2016 08jan2016
4 x 01jan2016 08jan2016
4 x 02jan2016 08jan2016
;
run;
data want;
 if _n_=1 then do;
   declare hash h();
   declare hiter hi('h');
   h.definekey('date');
   h.definedata('date','n');
   h.definedone();
   
   declare hash k();
   k.definekey('date');
   k.definedone();
 end;
do until(last.aes);
 set ae;
 by id aes;
 do date=stdt to aeendt;
  if h.find()=0 then do;n=n+1;h.replace();end;
    else do;n=1;h.add();end;
 end;
end;

do while(hi.next()=0);
  if n&amp;gt;1 then k.add();
end;

do until(last.aes);
 set ae;
 by id aes;
 do date=stdt to aeendt;
    if k.check()=0 then do;output;leave;end;
 end;
end;

h.clear();k.clear();
drop n date;
run;

proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Aug 2018 14:03:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-concurrence-dates/m-p/486350#M126533</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-08-13T14:03:45Z</dc:date>
    </item>
    <item>
      <title>Re: Extract concurrence dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-concurrence-dates/m-p/486734#M126695</link>
      <description>&lt;P&gt;hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp; Thank you very much, you are very helpful.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Aug 2018 15:52:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-concurrence-dates/m-p/486734#M126695</guid>
      <dc:creator>s_manoj</dc:creator>
      <dc:date>2018-08-14T15:52:13Z</dc:date>
    </item>
  </channel>
</rss>

