<?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: SAS calculate Date diff for rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-calculate-Date-diff-for-rows/m-p/850426#M336108</link>
    <description>&lt;P&gt;You can use this code which gives your desired output&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 306pt;" border="0" width="414" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 14.6pt;"&gt;
&lt;TD width="69" height="19" class="xl63" style="height: 14.6pt; width: 51pt; box-sizing: border-box; min-width: 40px;"&gt;Flow_typ&lt;/TD&gt;
&lt;TD width="69" class="xl63" style="border-left: none; width: 51pt;"&gt;Region&lt;/TD&gt;
&lt;TD width="69" class="xl63" style="border-left: none; width: 51pt;"&gt;Account_Status&lt;/TD&gt;
&lt;TD width="69" class="xl63" style="border-left: none; width: 51pt;"&gt;Amount&lt;/TD&gt;
&lt;TD width="69" class="xl63" style="border-left: none; width: 51pt;"&gt;St_date&lt;/TD&gt;
&lt;TD width="69" class="xl63" style="border-left: none; width: 51pt;"&gt;end_date&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.6pt;"&gt;
&lt;TD height="19" class="xl63" style="height: 14.6pt; border-top: none;"&gt;External&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;North&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;Closed&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;500&lt;/TD&gt;
&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;1/01/2024&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;01/31/2024&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.6pt;"&gt;
&lt;TD height="19" class="xl63" style="height: 14.6pt; border-top: none;"&gt;External&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;North&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;Closed&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;500&lt;/TD&gt;
&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;3/01/2026&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;05/31/2026&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.6pt;"&gt;
&lt;TD height="19" class="xl63" style="height: 14.6pt; border-top: none;"&gt;External&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;North&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;Closed&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;600&lt;/TD&gt;
&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;2/01/2024&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;02/28/2024&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.6pt;"&gt;
&lt;TD height="19" class="xl63" style="height: 14.6pt; border-top: none;"&gt;Internal&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;South&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;Open&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;100&lt;/TD&gt;
&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;1/01/2020&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;01/31/2020&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.6pt;"&gt;
&lt;TD height="19" class="xl63" style="height: 14.6pt; border-top: none;"&gt;Internal&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;South&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;Open&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;200&lt;/TD&gt;
&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;2/01/2021&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;02/28/2021&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.6pt;"&gt;
&lt;TD height="19" class="xl63" style="height: 14.6pt; border-top: none;"&gt;Internal&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;South&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;Open&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;200&lt;/TD&gt;
&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;5/01/2030&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;07/31/2030&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sort data = test1 out = test1;
by Flow_typ	Region	Account_Status	Amount St_date  end_date  ;
run;

/*array to compare previous vales to identify consecutive days*/

data test2;
set test1;
by Flow_typ	Region	Account_Status	Amount  ; 

array sdate(1); format sdate1  mmddyy10.; array edate(1); format edate1  mmddyy10.;
if first.amount then do;  i=1 ; 
		sdate(1)=st_date; edate(1)=end_date; 
		NewGroup=1; end;
	if i ne 1 then do; 
	if st_date ne edate(1)+1 then do;
		sdate(1)=st_date; edate(1)=end_date;   NewGroup=2; end;

		else 	if i ne 1 and  st_date = edate(1)+1 then do;   edate(1) = end_date; end;
		else NewGroup+1;
		end;
i + 1;
   retain sdate1 edate1 ;
   drop i;
run;

Proc sql;
Create table test3 as 
	Select distinct 
	Flow_typ, Region, Account_Status, Amount, min(sdate1) as St_date  format mmddyy10., Max(edate1) as end_date format mmddyy10.
	from 
	test2
	group by Flow_typ, Region, Account_Status, Amount,NewGroup /*instead of NewGroup sdate1*/

;Quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 20 Dec 2022 06:00:57 GMT</pubDate>
    <dc:creator>SK_11</dc:creator>
    <dc:date>2022-12-20T06:00:57Z</dc:date>
    <item>
      <title>SAS calculate Date diff for rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-calculate-Date-diff-for-rows/m-p/850375#M336078</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;I have a Table&amp;nbsp; test1 when values of variables Flow_typ,Region,Account_status and Amount are equal and diff between end date of first record and start date of next record is 1 then collapse all those records as 1 for that group (Flow_typ,Region,Account_status and Amount)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;when values of variables Flow_typ,Region,Account_status and Amount are equal and diff between end date of first record and start date of next record is &amp;gt; 1&amp;nbsp; then treat as different row&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output should be like Test2 .&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Test1&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Flow_typ&lt;/TD&gt;&lt;TD&gt;Region&lt;/TD&gt;&lt;TD&gt;Account_Status&lt;/TD&gt;&lt;TD&gt;Amount&lt;/TD&gt;&lt;TD&gt;St_date&lt;/TD&gt;&lt;TD&gt;end_date&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Internal&lt;/TD&gt;&lt;TD&gt;South&lt;/TD&gt;&lt;TD&gt;Open&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;1/1/2020&lt;/TD&gt;&lt;TD&gt;1/31/2020&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Internal&lt;/TD&gt;&lt;TD&gt;South&lt;/TD&gt;&lt;TD&gt;Open&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;TD&gt;2/1/2021&lt;/TD&gt;&lt;TD&gt;2/28/2021&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Internal&lt;/TD&gt;&lt;TD&gt;South&lt;/TD&gt;&lt;TD&gt;Open&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;TD&gt;5/1/2030&lt;/TD&gt;&lt;TD&gt;5/31/2030&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Internal&lt;/TD&gt;&lt;TD&gt;South&lt;/TD&gt;&lt;TD&gt;Open&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;TD&gt;6/1/2030&lt;/TD&gt;&lt;TD&gt;6/30/2030&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Internal&lt;/TD&gt;&lt;TD&gt;South&lt;/TD&gt;&lt;TD&gt;Open&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;TD&gt;7/1/2030&lt;/TD&gt;&lt;TD&gt;7/31/2030&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;External&lt;/TD&gt;&lt;TD&gt;North&lt;/TD&gt;&lt;TD&gt;Closed&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;TD&gt;1/1/2024&lt;/TD&gt;&lt;TD&gt;1/31/2024&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;External&lt;/TD&gt;&lt;TD&gt;North&lt;/TD&gt;&lt;TD&gt;Closed&lt;/TD&gt;&lt;TD&gt;60&lt;/TD&gt;&lt;TD&gt;2/1/2024&lt;/TD&gt;&lt;TD&gt;2/28/2024&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;External&lt;/TD&gt;&lt;TD&gt;North&lt;/TD&gt;&lt;TD&gt;Closed&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;TD&gt;3/1/2026&lt;/TD&gt;&lt;TD&gt;3/31/2026&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;External&lt;/TD&gt;&lt;TD&gt;North&lt;/TD&gt;&lt;TD&gt;Closed&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;TD&gt;4/1/2026&lt;/TD&gt;&lt;TD&gt;4/30/2026&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;External&lt;/TD&gt;&lt;TD&gt;North&lt;/TD&gt;&lt;TD&gt;Closed&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;TD&gt;5/1/2026&lt;/TD&gt;&lt;TD&gt;5/31/2026&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone please help me . Thanks in Advance&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Test 2&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Flow_typ&lt;/TD&gt;&lt;TD&gt;Region&lt;/TD&gt;&lt;TD&gt;Account_Status&lt;/TD&gt;&lt;TD&gt;Amount&lt;/TD&gt;&lt;TD&gt;St_date&lt;/TD&gt;&lt;TD&gt;end_date&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Internal&lt;/TD&gt;&lt;TD&gt;South&lt;/TD&gt;&lt;TD&gt;Open&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;1/1/2020&lt;/TD&gt;&lt;TD&gt;1/31/2020&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Internal&lt;/TD&gt;&lt;TD&gt;South&lt;/TD&gt;&lt;TD&gt;Open&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;TD&gt;2/1/2021&lt;/TD&gt;&lt;TD&gt;2/28/2021&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Internal&lt;/TD&gt;&lt;TD&gt;South&lt;/TD&gt;&lt;TD&gt;Open&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;TD&gt;5/1/2030&lt;/TD&gt;&lt;TD&gt;7/31/2030&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;External&lt;/TD&gt;&lt;TD&gt;North&lt;/TD&gt;&lt;TD&gt;Closed&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;TD&gt;1/1/2024&lt;/TD&gt;&lt;TD&gt;1/31/2024&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;External&lt;/TD&gt;&lt;TD&gt;North&lt;/TD&gt;&lt;TD&gt;Closed&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;TD&gt;3/1/2026&lt;/TD&gt;&lt;TD&gt;5/31/2026&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;External&lt;/TD&gt;&lt;TD&gt;North&lt;/TD&gt;&lt;TD&gt;Closed&lt;/TD&gt;&lt;TD&gt;60&lt;/TD&gt;&lt;TD&gt;2/1/2024&lt;/TD&gt;&lt;TD&gt;2/28/2024&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Mon, 19 Dec 2022 19:38:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-calculate-Date-diff-for-rows/m-p/850375#M336078</guid>
      <dc:creator>jhh197</dc:creator>
      <dc:date>2022-12-19T19:38:45Z</dc:date>
    </item>
    <item>
      <title>Re: SAS calculate Date diff for rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-calculate-Date-diff-for-rows/m-p/850399#M336095</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's not so difficult.&lt;BR /&gt;Can you give us the source table (i.e. the top one) as a data step with datalines (cards)?&lt;/P&gt;
&lt;P&gt;When pasting your data step SAS code in the communities ...&lt;/P&gt;
&lt;P&gt;, click the "running man icon" in the toolbar on top and paste your code in the pop-up window.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Mon, 19 Dec 2022 22:03:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-calculate-Date-diff-for-rows/m-p/850399#M336095</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2022-12-19T22:03:35Z</dc:date>
    </item>
    <item>
      <title>Re: SAS calculate Date diff for rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-calculate-Date-diff-for-rows/m-p/850407#M336097</link>
      <description>&lt;P&gt;This is extremely similar to your other question: &lt;A href="https://communities.sas.com/t5/SAS-Programming/SAS-Row-by-row-compare/m-p/849017#M335681" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/SAS-Row-by-row-compare/m-p/849017#M335681&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;The only difference is comparing an additional variable which would be done with a LAGged value to collapse the values.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Dec 2022 22:56:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-calculate-Date-diff-for-rows/m-p/850407#M336097</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-12-19T22:56:32Z</dc:date>
    </item>
    <item>
      <title>Re: SAS calculate Date diff for rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-calculate-Date-diff-for-rows/m-p/850408#M336098</link>
      <description>Can you please help me with the code thank you</description>
      <pubDate>Mon, 19 Dec 2022 22:59:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-calculate-Date-diff-for-rows/m-p/850408#M336098</guid>
      <dc:creator>jhh197</dc:creator>
      <dc:date>2022-12-19T22:59:07Z</dc:date>
    </item>
    <item>
      <title>Re: SAS calculate Date diff for rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-calculate-Date-diff-for-rows/m-p/850409#M336099</link>
      <description>data test1;&lt;BR /&gt;input Flow_typ$ 1-9 Region$ 10-15 Account_Status$16-22 Amount 24-27 &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/369750"&gt;@28&lt;/a&gt; St_date mmddyy10. &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/295629"&gt;@37&lt;/a&gt; end_date mmddyy10.;&lt;BR /&gt;informat St_date mmddyy10. end_date mmddyy10.;&lt;BR /&gt;format St_date mmddyy10. end_date mmddyy10.;&lt;BR /&gt;cards;&lt;BR /&gt;Internal South Open 100 1/1/2020 1/31/2020&lt;BR /&gt;Internal South Open 200 2/1/2021 2/28/2021&lt;BR /&gt;Internal South Open 200 5/1/2030 5/31/2030&lt;BR /&gt;Internal South Open 200 6/1/2030 6/30/2030&lt;BR /&gt;Internal South Open 200 7/1/2030 7/31/2030&lt;BR /&gt;External North Closed 500 1/1/2024 1/31/2024&lt;BR /&gt;External North Closed 600 2/1/2024 2/28/2024&lt;BR /&gt;External North Closed 500 3/1/2026 3/31/2026&lt;BR /&gt;External North Closed 500 4/1/2026 4/30/2026&lt;BR /&gt;External North Closed 500 5/1/2026 5/31/2026&lt;BR /&gt;run;</description>
      <pubDate>Mon, 19 Dec 2022 23:05:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-calculate-Date-diff-for-rows/m-p/850409#M336099</guid>
      <dc:creator>jhh197</dc:creator>
      <dc:date>2022-12-19T23:05:54Z</dc:date>
    </item>
    <item>
      <title>Re: SAS calculate Date diff for rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-calculate-Date-diff-for-rows/m-p/850410#M336100</link>
      <description>you can use 500, 600 as amounts instead of 50 and 60</description>
      <pubDate>Mon, 19 Dec 2022 23:09:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-calculate-Date-diff-for-rows/m-p/850410#M336100</guid>
      <dc:creator>jhh197</dc:creator>
      <dc:date>2022-12-19T23:09:04Z</dc:date>
    </item>
    <item>
      <title>Re: SAS calculate Date diff for rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-calculate-Date-diff-for-rows/m-p/850426#M336108</link>
      <description>&lt;P&gt;You can use this code which gives your desired output&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 306pt;" border="0" width="414" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 14.6pt;"&gt;
&lt;TD width="69" height="19" class="xl63" style="height: 14.6pt; width: 51pt; box-sizing: border-box; min-width: 40px;"&gt;Flow_typ&lt;/TD&gt;
&lt;TD width="69" class="xl63" style="border-left: none; width: 51pt;"&gt;Region&lt;/TD&gt;
&lt;TD width="69" class="xl63" style="border-left: none; width: 51pt;"&gt;Account_Status&lt;/TD&gt;
&lt;TD width="69" class="xl63" style="border-left: none; width: 51pt;"&gt;Amount&lt;/TD&gt;
&lt;TD width="69" class="xl63" style="border-left: none; width: 51pt;"&gt;St_date&lt;/TD&gt;
&lt;TD width="69" class="xl63" style="border-left: none; width: 51pt;"&gt;end_date&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.6pt;"&gt;
&lt;TD height="19" class="xl63" style="height: 14.6pt; border-top: none;"&gt;External&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;North&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;Closed&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;500&lt;/TD&gt;
&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;1/01/2024&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;01/31/2024&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.6pt;"&gt;
&lt;TD height="19" class="xl63" style="height: 14.6pt; border-top: none;"&gt;External&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;North&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;Closed&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;500&lt;/TD&gt;
&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;3/01/2026&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;05/31/2026&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.6pt;"&gt;
&lt;TD height="19" class="xl63" style="height: 14.6pt; border-top: none;"&gt;External&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;North&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;Closed&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;600&lt;/TD&gt;
&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;2/01/2024&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;02/28/2024&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.6pt;"&gt;
&lt;TD height="19" class="xl63" style="height: 14.6pt; border-top: none;"&gt;Internal&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;South&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;Open&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;100&lt;/TD&gt;
&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;1/01/2020&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;01/31/2020&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.6pt;"&gt;
&lt;TD height="19" class="xl63" style="height: 14.6pt; border-top: none;"&gt;Internal&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;South&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;Open&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;200&lt;/TD&gt;
&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;2/01/2021&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;02/28/2021&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.6pt;"&gt;
&lt;TD height="19" class="xl63" style="height: 14.6pt; border-top: none;"&gt;Internal&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;South&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;Open&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;200&lt;/TD&gt;
&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;"&gt;5/01/2030&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;07/31/2030&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sort data = test1 out = test1;
by Flow_typ	Region	Account_Status	Amount St_date  end_date  ;
run;

/*array to compare previous vales to identify consecutive days*/

data test2;
set test1;
by Flow_typ	Region	Account_Status	Amount  ; 

array sdate(1); format sdate1  mmddyy10.; array edate(1); format edate1  mmddyy10.;
if first.amount then do;  i=1 ; 
		sdate(1)=st_date; edate(1)=end_date; 
		NewGroup=1; end;
	if i ne 1 then do; 
	if st_date ne edate(1)+1 then do;
		sdate(1)=st_date; edate(1)=end_date;   NewGroup=2; end;

		else 	if i ne 1 and  st_date = edate(1)+1 then do;   edate(1) = end_date; end;
		else NewGroup+1;
		end;
i + 1;
   retain sdate1 edate1 ;
   drop i;
run;

Proc sql;
Create table test3 as 
	Select distinct 
	Flow_typ, Region, Account_Status, Amount, min(sdate1) as St_date  format mmddyy10., Max(edate1) as end_date format mmddyy10.
	from 
	test2
	group by Flow_typ, Region, Account_Status, Amount,NewGroup /*instead of NewGroup sdate1*/

;Quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Dec 2022 06:00:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-calculate-Date-diff-for-rows/m-p/850426#M336108</guid>
      <dc:creator>SK_11</dc:creator>
      <dc:date>2022-12-20T06:00:57Z</dc:date>
    </item>
    <item>
      <title>Re: SAS calculate Date diff for rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-calculate-Date-diff-for-rows/m-p/850455#M336110</link>
      <description>&lt;P&gt;If I understood what you mean.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1;
input Flow_typ $  Region $  Account_Status $ Amount St_date : mmddyy10. end_date : mmddyy10.;
informat St_date mmddyy10. end_date mmddyy10.;
format St_date mmddyy10. end_date mmddyy10.;
cards;
Internal South Open 100 1/1/2020 1/31/2020
Internal South Open 200 2/1/2021 2/28/2021
Internal South Open 200 5/1/2030 5/31/2030
Internal South Open 200 6/1/2030 6/30/2030
Internal South Open 200 7/1/2030 7/31/2030
External North Closed 500 1/1/2024 1/31/2024
External North Closed 600 2/1/2024 2/28/2024
External North Closed 500 3/1/2026 3/31/2026
External North Closed 500 4/1/2026 4/30/2026
External North Closed 500 5/1/2026 5/31/2026
;
run;
proc sort data=test1 out=temp;
by Flow_typ   Region   Account_Status  Amount St_date;
run;
data temp;
 set temp;
 by Flow_typ   Region   Account_Status  Amount;
if first.amount or st_date-lag(end_date) ne 1 then group+1;
run;
proc sql;
create table want as
select Flow_typ,   Region  , Account_Status , Amount,
min(st_Date) as st_date format=mmddyy10.,max(end_date) as end_date format=mmddyy10.
 from temp
  group by Flow_typ,   Region  , Account_Status , Amount,group;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Dec 2022 08:31:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-calculate-Date-diff-for-rows/m-p/850455#M336110</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-12-20T08:31:39Z</dc:date>
    </item>
    <item>
      <title>Re: SAS calculate Date diff for rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-calculate-Date-diff-for-rows/m-p/850727#M336193</link>
      <description>Thank you so much for all your help</description>
      <pubDate>Thu, 22 Dec 2022 06:39:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-calculate-Date-diff-for-rows/m-p/850727#M336193</guid>
      <dc:creator>jhh197</dc:creator>
      <dc:date>2022-12-22T06:39:06Z</dc:date>
    </item>
    <item>
      <title>Re: SAS calculate Date diff for rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-calculate-Date-diff-for-rows/m-p/850728#M336194</link>
      <description>Thank you so much for all help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Thu, 22 Dec 2022 06:39:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-calculate-Date-diff-for-rows/m-p/850728#M336194</guid>
      <dc:creator>jhh197</dc:creator>
      <dc:date>2022-12-22T06:39:48Z</dc:date>
    </item>
  </channel>
</rss>

