<?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: Calculating length of interruptions between dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculating-length-of-interruptions-between-dates/m-p/244420#M45550</link>
    <description>&lt;P&gt;Hello PGStats, your code worked exactly the way I needed! Thank you very much! I have never seen an until function before, but it makes things MUCH eaier than the do loops I was trying to do before! Glad to learn something new!&lt;/P&gt;</description>
    <pubDate>Tue, 19 Jan 2016 13:27:24 GMT</pubDate>
    <dc:creator>daszlosek</dc:creator>
    <dc:date>2016-01-19T13:27:24Z</dc:date>
    <item>
      <title>Calculating length of interruptions between dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-length-of-interruptions-between-dates/m-p/244299#M45511</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to calculate the length and number of interruptions between dates for each subject ID.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the an example of what the data looks like in explorer:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="160"&gt;
&lt;P&gt;usubjid&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;startdate&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;enddate&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="160"&gt;
&lt;P&gt;12&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;2009-03-25&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;2010-10-26&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="160"&gt;
&lt;P&gt;12&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;2010-10-30&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;2011-01-30&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="160"&gt;
&lt;P&gt;12&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;2011-02-15&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;2011-03-16&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="160"&gt;
&lt;P&gt;13&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;2010-12-11&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;2011-01-13&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="160"&gt;
&lt;P&gt;13&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;2011-04-13&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;2011-07-30&lt;/P&gt;
&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;For each subjectid, I would like to know the total number of interruptions and the total length of each interruptions.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your help!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Donald S.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jan 2016 21:23:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-length-of-interruptions-between-dates/m-p/244299#M45511</guid>
      <dc:creator>daszlosek</dc:creator>
      <dc:date>2016-01-18T21:23:32Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating length of interruptions between dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-length-of-interruptions-between-dates/m-p/244301#M45512</link>
      <description>&lt;P&gt;Could you give example of your desired output based on the data you posted?&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jan 2016 21:36:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-length-of-interruptions-between-dates/m-p/244301#M45512</guid>
      <dc:creator>mohamed_zaki</dc:creator>
      <dc:date>2016-01-18T21:36:04Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating length of interruptions between dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-length-of-interruptions-between-dates/m-p/244303#M45514</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes Here is an example of the output, I also included how I would like to calculate the length:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="896"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="84"&gt;
&lt;P&gt;usubjid&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="176"&gt;
&lt;P&gt;startdate&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="138"&gt;
&lt;P&gt;enddate&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="105"&gt;
&lt;P&gt;# of interruptions&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="219"&gt;
&lt;P&gt;&amp;nbsp;Calc length&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="173"&gt;
&lt;P&gt;&amp;nbsp;Length of Interruption&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="84"&gt;
&lt;P&gt;12&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="176"&gt;
&lt;P&gt;3/25/2009&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="138"&gt;
&lt;P&gt;10/26/2010&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="105"&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="219"&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="173"&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="84"&gt;
&lt;P&gt;12&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="176"&gt;
&lt;P&gt;10/30/2010&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="138"&gt;
&lt;P&gt;1/30/2011&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="105"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="219"&gt;
&lt;P&gt;10/30/2010 - 10/26/2010&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="173"&gt;
&lt;P&gt;4&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="84"&gt;
&lt;P&gt;12&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="176"&gt;
&lt;P&gt;2/15/2011&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="138"&gt;
&lt;P&gt;3/16/2011&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="105"&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="219"&gt;
&lt;P&gt;&amp;nbsp;2/15/2011 - 1/30/2011&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="173"&gt;
&lt;P&gt;16&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="84"&gt;
&lt;P&gt;13&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="176"&gt;
&lt;P&gt;12/11/2010&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="138"&gt;
&lt;P&gt;1/13/2011&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="105"&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="219"&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="173"&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="84"&gt;
&lt;P&gt;13&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="176"&gt;
&lt;P&gt;4/13/2011&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="138"&gt;
&lt;P&gt;7/30/2011&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="105"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="219"&gt;
&lt;P&gt;&amp;nbsp;4/13/2011 - 1/13/2011&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="173"&gt;
&lt;P&gt;90&lt;/P&gt;
&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 hope this made things a little clearer,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Donald S.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jan 2016 21:47:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-length-of-interruptions-between-dates/m-p/244303#M45514</guid>
      <dc:creator>daszlosek</dc:creator>
      <dc:date>2016-01-18T21:47:30Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating length of interruptions between dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-length-of-interruptions-between-dates/m-p/244317#M45518</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
format startdate  enddate YYMMDD10.;
input usubjid startdate :YYMMDD10. enddate: YYMMDD10.;
datalines;
12	2009-03-25	2010-10-26
12	2010-10-30	2011-01-30
12	2011-02-15	2011-03-16
13	2010-12-11	2011-01-13
13	2011-04-13	2011-07-30
;

proc sort data = have;
by usubjid startdate;
run;

data want;
do until(last.usubjid);
    set have; by usubjid;
    call missing(daysInterruptions);
    if not missing(lastDate) then do;
        if startDate &amp;gt; lastDate then do;
            nbInterruptions = sum(nbInterruptions, 1);
            daysInterruptions = intck("DAY", lastDate, startDate);
            end;
        end;
    output;
    lastDate = endDate;
    end;
drop lastDate;
run; 

proc print data=want noobs; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Jan 2016 23:29:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-length-of-interruptions-between-dates/m-p/244317#M45518</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-01-18T23:29:10Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating length of interruptions between dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-length-of-interruptions-between-dates/m-p/244325#M45522</link>
      <description>&lt;P&gt;Please try this alternative method&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by usubjid;
prevdate=lag(enddate);
if first.usubjid then prevdate=.;
Length_of_Interruption=intck('day',prevdate,startdate);
format prevdate date9.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Jan 2016 00:43:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-length-of-interruptions-between-dates/m-p/244325#M45522</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2016-01-19T00:43:25Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating length of interruptions between dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-length-of-interruptions-between-dates/m-p/244343#M45529</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards expandtabs truncover;
format startdate  enddate YYMMDD10.;
input usubjid startdate :YYMMDD10. enddate: YYMMDD10.;
datalines;
12	2009-03-25	2010-10-26
12	2010-10-30	2011-01-30
12	2011-02-15	2011-03-16
13	2010-12-11	2011-01-13
13	2011-04-13	2011-07-30
;

proc sort data = have;
by usubjid startdate;
run;
data want;
 set have;
 by usubjid ;
 lag_enddate=lag(enddate) ;
 if first.usubjid  then group=0;
  else if startdate gt lag_enddate then do;
    group+1;
    n=group;
    dif=startdate - lag_enddate;
  end;
 drop lag_enddate group;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Jan 2016 02:50:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-length-of-interruptions-between-dates/m-p/244343#M45529</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-01-19T02:50:46Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating length of interruptions between dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-length-of-interruptions-between-dates/m-p/244420#M45550</link>
      <description>&lt;P&gt;Hello PGStats, your code worked exactly the way I needed! Thank you very much! I have never seen an until function before, but it makes things MUCH eaier than the do loops I was trying to do before! Glad to learn something new!&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2016 13:27:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-length-of-interruptions-between-dates/m-p/244420#M45550</guid>
      <dc:creator>daszlosek</dc:creator>
      <dc:date>2016-01-19T13:27:24Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating length of interruptions between dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-length-of-interruptions-between-dates/m-p/244422#M45552</link>
      <description>Hello Jag,&lt;BR /&gt;&lt;BR /&gt;Your way also works as a correct solution!&lt;BR /&gt;&lt;BR /&gt;Thank you very much!</description>
      <pubDate>Tue, 19 Jan 2016 13:33:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-length-of-interruptions-between-dates/m-p/244422#M45552</guid>
      <dc:creator>daszlosek</dc:creator>
      <dc:date>2016-01-19T13:33:52Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating length of interruptions between dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-length-of-interruptions-between-dates/m-p/244844#M45664</link>
      <description>&lt;P&gt;Just a remark: There is no "UNTIL &lt;EM&gt;function&lt;/EM&gt;", but only the&amp;nbsp;&lt;A href="http://support.sas.com/documentation/cdl/en/syntaxidx/68719/HTML/default/index.htm#/documentation/cdl//en/lestmtsref/68024/HTML/default/p1021qt3a3n8m2n1vh11ggzhu57n.htm" target="_blank"&gt;&lt;EM&gt;DO&lt;/EM&gt; UNTIL &lt;EM&gt;statement&lt;/EM&gt;&lt;/A&gt;, which marks the beginning of a loop in which statements are executed repetitively &lt;EM&gt;until&lt;/EM&gt; a condition is true. This exit&amp;nbsp;condition&amp;nbsp;is written in parentheses after the UNTIL keyword -- a notation which in fact resembles that of a function call.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;PG used this DO UNTIL loop in a special way: &lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;do until(last.&lt;EM&gt;varname&lt;/EM&gt;);
  set &lt;EM&gt;dataset&lt;/EM&gt;;
  by &lt;EM&gt;varname&lt;/EM&gt;;
  ...
end;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;This&amp;nbsp;and&amp;nbsp;similar constructs are known as&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;EM&gt;DOW&lt;/EM&gt; loops." Here's an introductory paper on this useful, somewhat advanced SAS programming technique:&amp;nbsp;&lt;/SPAN&gt;&lt;A href="http://www2.sas.com/proceedings/sugi28/099-28.pdf" target="_blank" rel="nofollow"&gt;http://www2.sas.com/proceedings/sugi28/099-28.pdf&lt;/A&gt;&lt;SPAN&gt;. There are more on the web, just search for "DOW loop" SAS.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2016 23:40:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-length-of-interruptions-between-dates/m-p/244844#M45664</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-01-20T23:40:39Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating length of interruptions between dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-length-of-interruptions-between-dates/m-p/245172#M45717</link>
      <description>Thank you FreelanceReinhard, I look forward to reading this!</description>
      <pubDate>Thu, 21 Jan 2016 13:35:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-length-of-interruptions-between-dates/m-p/245172#M45717</guid>
      <dc:creator>daszlosek</dc:creator>
      <dc:date>2016-01-21T13:35:46Z</dc:date>
    </item>
  </channel>
</rss>

