<?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 Time from Conditional by ID in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Time-from-Conditional-by-ID/m-p/344782#M79257</link>
    <description>&lt;P&gt;My apologies, I just left that variable in there from a different datalines statement. It has no significance.&lt;/P&gt;</description>
    <pubDate>Mon, 27 Mar 2017 20:24:45 GMT</pubDate>
    <dc:creator>jckbnimble</dc:creator>
    <dc:date>2017-03-27T20:24:45Z</dc:date>
    <item>
      <title>Calculate Time from Conditional by ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Time-from-Conditional-by-ID/m-p/344746#M79244</link>
      <description>&lt;P&gt;Hello I would like to calculate the time post-treatment but I have pre-treatment data and sometimes there are collection dates before or inbetween pre/post treatment flag. I want to have days post treatment with day 0 being the post date flag.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input ID $ NO Treatment $ &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30987"&gt;@11&lt;/a&gt; DATE MMDDYY10.;&lt;BR /&gt;FORMAT DATE DATE9.;&lt;BR /&gt;cards;&lt;BR /&gt;1 44 Pre 10/21/2015&lt;BR /&gt;1 44 _ 10/22/2015&lt;BR /&gt;1 28 Post 10/23/2015&lt;BR /&gt;1 22 _ 11/23/2015&lt;BR /&gt;2 35 Pre 9/21/2015&lt;BR /&gt;2 35 Post 10/21/2015&lt;BR /&gt;2 35 _ 10/26/2015&lt;BR /&gt;2 35 _ 10/31/2015&lt;BR /&gt;3 35 _ 5/11/2015&lt;BR /&gt;3 35 Pre 5/16/2015&lt;BR /&gt;3 35 Post 6/22/2015&lt;BR /&gt;3 35 Post 6/27/2015&lt;BR /&gt;;;;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data want;&lt;BR /&gt;input ID $ NO Treatment $ &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30987"&gt;@11&lt;/a&gt; DATE MMDDYY10. TIME;&lt;BR /&gt;FORMAT DATE DATE9.;&lt;BR /&gt;cards;&lt;BR /&gt;1 44 Pre 10/21/2015 .&lt;BR /&gt;1 44 _ 10/22/2015 .&lt;BR /&gt;1 28 Post 10/23/2015 0&lt;BR /&gt;1 22 _ 11/23/2015 29&lt;BR /&gt;2 35 Pre 9/21/2015 .&lt;BR /&gt;2 35 Post 10/21/2015 0&lt;BR /&gt;2 35 _ 10/26/2015 5&lt;BR /&gt;2 35 _ 10/31/2015 10&lt;BR /&gt;3 35 _ 5/11/2015 .&lt;BR /&gt;3 35 Pre 5/16/2015 .&lt;BR /&gt;3 35 Post 6/22/2015 0&lt;BR /&gt;3 35 Post 6/27/2015 5&lt;BR /&gt;;;;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2017 19:22:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Time-from-Conditional-by-ID/m-p/344746#M79244</guid>
      <dc:creator>jckbnimble</dc:creator>
      <dc:date>2017-03-27T19:22:58Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Time from Conditional by ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Time-from-Conditional-by-ID/m-p/344775#M79253</link>
      <description>&lt;P&gt;Is&lt;/P&gt;
&lt;P&gt;1 22 _ 11/23/2015&lt;/P&gt;
&lt;P&gt;supposed to be&lt;/P&gt;
&lt;P&gt;1 28 _ 11/23/2015&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If not what role may the NO variable play in the logic of assignment, if any?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also what is the rule involved for that last pair&lt;/P&gt;
&lt;P&gt;3 35 Post 6/22/2015 0&lt;BR /&gt;3 35 Post 6/27/2015 5&lt;/P&gt;
&lt;P&gt;where&amp;nbsp; the second has a 5 instead of 0??? it is a Post date and would expect it to be 0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And post example code into CODE boxes opened with the forum {i} icon. Your example data sets will not run as the forum reformatted things so that the date does not always start at column 11.&lt;/P&gt;
&lt;P&gt;This does work:&lt;/P&gt;
&lt;PRE&gt;data have;
   informat id $4. no best4. treatment $4. date mmddyy10.;
   input ID  NO Treatment  DATE;
   FORMAT DATE DATE9.;
cards;
1 44 Pre 10/21/2015
1 44 _ 10/22/2015
1 28 Post 10/23/2015
1 22 _ 11/23/2015
2 35 Pre 9/21/2015
2 35 Post 10/21/2015
2 35 _ 10/26/2015
2 35 _ 10/31/2015
3 35 _ 5/11/2015
3 35 Pre 5/16/2015
3 35 Post 6/22/2015
3 35 Post 6/27/2015
;;;;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And Oct 23 to Nov 23 will be 31 days not 29.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2017 20:29:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Time-from-Conditional-by-ID/m-p/344775#M79253</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-27T20:29:12Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Time from Conditional by ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Time-from-Conditional-by-ID/m-p/344782#M79257</link>
      <description>&lt;P&gt;My apologies, I just left that variable in there from a different datalines statement. It has no significance.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2017 20:24:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Time-from-Conditional-by-ID/m-p/344782#M79257</guid>
      <dc:creator>jckbnimble</dc:creator>
      <dc:date>2017-03-27T20:24:45Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Time from Conditional by ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Time-from-Conditional-by-ID/m-p/344786#M79259</link>
      <description>&lt;P&gt;This almost works barring a description of why the last POST doesn't reset the counter to 0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   by id date;
   retain postdate postflag;
   if first.id then do;
      postdate=.; /* date of the most recent Post record*/
      postflag=0; /* flag for has the "post" been found*/
   end;
   if treatment = 'Pre' then do;
      postflag=0;
      postdate=.;
   end;

   if treatment = 'Post' then do;
      postflag=1;
      postdate=date;
   end;
   time = date-postdate;
   drop postdate postflag;
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Mar 2017 20:31:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Time-from-Conditional-by-ID/m-p/344786#M79259</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-27T20:31:35Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Time from Conditional by ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Time-from-Conditional-by-ID/m-p/344798#M79264</link>
      <description>&lt;P&gt;Works like a charm!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2017 21:03:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Time-from-Conditional-by-ID/m-p/344798#M79264</guid>
      <dc:creator>jckbnimble</dc:creator>
      <dc:date>2017-03-27T21:03:28Z</dc:date>
    </item>
  </channel>
</rss>

