<?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: Calculate difference in days between two dates for all possible pairwise date combinations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculate-difference-in-days-between-two-dates-for-all-possible/m-p/562035#M157404</link>
    <description>Thank you PaigeMiller, its exactly what I was looking for.</description>
    <pubDate>Tue, 28 May 2019 17:58:11 GMT</pubDate>
    <dc:creator>Solsidan</dc:creator>
    <dc:date>2019-05-28T17:58:11Z</dc:date>
    <item>
      <title>Calculate difference in days between two dates for all possible pairwise date combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-difference-in-days-between-two-dates-for-all-possible/m-p/561983#M157391</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;I need your help in solving a problem using SAS. I am interested in calculating the difference in the number of days between all possible pairwise date combinations (from Date_1 to Date_7) for each id.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The eventual goal is to have a single variable indicator ("&lt;STRONG&gt;lessthan400days&lt;/STRONG&gt;") per id that takes the value of 1 if the difference for ANY pairwise combination is less than 400 days, value = 0 if all possible pairwise combinations are greater, value = . if there is less than two dates for all date range (date_1 to date_7) e.g. variable&amp;nbsp;lessthan400days for id = 1 would be lessthan400days = 1 because the date pairs (date_1 and date_5) has 107 days, or pairs (date_3 and date_4) has 308 days. For ids 4 and 5, variable lessthan400days = .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So here are some tips to work with:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;No need to store the actual calculation results between the pair combinations.&lt;/LI&gt;&lt;LI&gt;If any pair combination is less than or equal to 400, the calculations can stop for that id.&lt;/LI&gt;&lt;LI&gt;If for an id there is only one date variable, or all dates are missing i.e. no pair e.g. ids 4 and 5, then set value to missing (".")&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have looked at posts that calculate date differences but none seems to do what I hope to achieve.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I shall greatly appreciate your help!&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;&lt;CODE class=" language-sas"&gt;data have;
input id (Date_1-Date_7) (: yymmdd10.) ;
format Date_1-Date_7 yymmdd10.;
cards;
1     2005/07/28  2016/12/23  2011/03/29  2012/01/30  2005/11/11  2016/12/23  2014/04/10
2     2006/06/16  2005/07/13  2007/06/27  2007/06/19  2005/07/13  2010/10/29  2015/09/29
3     2011/08/19  2010/04/12  2010/04/12  2012/08/21  2007/01/12  2015/12/18  2011/09/09
4     .  .  .  .  .  .  .
5     .  2016/01/21  .  .  .  .  .
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 May 2019 14:36:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-difference-in-days-between-two-dates-for-all-possible/m-p/561983#M157391</guid>
      <dc:creator>Solsidan</dc:creator>
      <dc:date>2019-05-28T14:36:11Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate difference in days between two dates for all possible pairwise date combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-difference-in-days-between-two-dates-for-all-possible/m-p/561985#M157393</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id (Date_1-Date_7) (: yymmdd10.) ;
array d date_1-date_7;
flag=.;
do i=1 to dim(d)-1;
	do j=(i+1) to dim(d);
	    if not missing(d(j)) and not missing(d(i)) and abs(d(j)-d(i)) &amp;lt; 400 then do;
                flag=1; 
                leave;
            end;
	end;
end;
format Date_1-Date_7 yymmdd10.;
drop i j;
cards;
1     2005/07/28  2016/12/23  2011/03/29  2012/01/30  2005/11/11  2016/12/23  2014/04/10
2     2006/06/16  2005/07/13  2007/06/27  2007/06/19  2005/07/13  2010/10/29  2015/09/29
3     2011/08/19  2010/04/12  2010/04/12  2012/08/21  2007/01/12  2015/12/18  2011/09/09
4     .  .  .  .  .  .  .
5     .  2016/01/21  .  .  .  .  .
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 May 2019 14:57:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-difference-in-days-between-two-dates-for-all-possible/m-p/561985#M157393</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-05-28T14:57:03Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate difference in days between two dates for all possible pairwise date combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-difference-in-days-between-two-dates-for-all-possible/m-p/562035#M157404</link>
      <description>Thank you PaigeMiller, its exactly what I was looking for.</description>
      <pubDate>Tue, 28 May 2019 17:58:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-difference-in-days-between-two-dates-for-all-possible/m-p/562035#M157404</guid>
      <dc:creator>Solsidan</dc:creator>
      <dc:date>2019-05-28T17:58:11Z</dc:date>
    </item>
  </channel>
</rss>

