<?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: date add days in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/date-add-days/m-p/648626#M194340</link>
    <description>&lt;P&gt;Start by reading the log and fixing the syntax errors. Your code misses a semicolon.&lt;/P&gt;</description>
    <pubDate>Mon, 18 May 2020 16:58:14 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-05-18T16:58:14Z</dc:date>
    <item>
      <title>date add days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-add-days/m-p/648612#M194333</link>
      <description>&lt;P&gt;Hi My current dataset looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;start_date_time&lt;/TD&gt;&lt;TD&gt;stop_date_time&lt;/TD&gt;&lt;TD&gt;discharge&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1234&lt;/TD&gt;&lt;TD&gt;4/4/2020 12:42&lt;/TD&gt;&lt;TD&gt;4/9/2020 12:11&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4567&lt;/TD&gt;&lt;TD&gt;8/1/2019 19:12&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;8910&lt;/TD&gt;&lt;TD&gt;8/2/2019 18:12&lt;/TD&gt;&lt;TD&gt;8/11/2019 18:12&lt;/TD&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;WHat I would like to do&lt;/P&gt;&lt;P&gt;if discharge &amp;lt; 7 then new_stop_date_time = stop_date_time&lt;/P&gt;&lt;P&gt;else if discharge &amp;gt;= 7 then new_stop_date_time&amp;nbsp; =&amp;nbsp;stop_date_time&lt;/P&gt;&lt;P&gt;else if discharge = . then&amp;nbsp;new_stop_date_time&amp;nbsp; = start_date_time + 7 days&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried the following&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data o.time_to_first_event2; set o.time_to_first_event;&lt;BR /&gt;if discharge &amp;lt; 7 then new_stop_date_time= stop_date_time;&lt;BR /&gt;else if discharge &amp;gt;= 7 then new_stop_date_time= stop_date_time;&lt;BR /&gt;else discharge=. then new_stop_date_time= intnx('dtday', start_date_time, 7);&lt;BR /&gt;format new_stop_date_time DATETIME16.;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Not working!&amp;nbsp;&lt;/P&gt;&lt;P&gt;discharge is in&amp;nbsp;BEST12. format&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 May 2020 16:11:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-add-days/m-p/648612#M194333</guid>
      <dc:creator>radhikaa4</dc:creator>
      <dc:date>2020-05-18T16:11:42Z</dc:date>
    </item>
    <item>
      <title>Re: date add days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-add-days/m-p/648619#M194337</link>
      <description>&lt;P&gt;Doesn't work is awful vague.&lt;BR /&gt;&lt;BR /&gt;Are there errors in the log?: Post the code and log in a code box opened with the &amp;lt;&amp;gt; to maintain formatting of error messages.&lt;BR /&gt;&lt;BR /&gt;No output? Post any log in a code box.&lt;BR /&gt;&lt;BR /&gt;Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat&lt;/A&gt;... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the &amp;lt;&amp;gt; icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One common problem we all learn with SAS is that missing is "less than everything". So you may need something like:&lt;/P&gt;
&lt;PRE&gt;data o.time_to_first_event2; set o.time_to_first_event;

if  &lt;STRONG&gt;0 &amp;lt;=&lt;/STRONG&gt; discharge &amp;lt; 7 then new_stop_date_time= stop_date_time;
else if discharge &amp;gt;= 7 then new_stop_date_time= stop_date_time;
else discharge=. then new_stop_date_time= intnx('dtday', start_date_time, 7);
format new_stop_date_time DATETIME16.;
run;&lt;/PRE&gt;
&lt;P&gt;Pick a reasonable value for the "0 &amp;lt;= discharge" I show above.&lt;/P&gt;
&lt;P&gt;Or you could preface the If/then with something like:&lt;/P&gt;
&lt;PRE&gt;data o.time_to_first_event2; set o.time_to_first_event;
if not missing(discharge) then do;
   if discharge &amp;lt; 7 then new_stop_date_time= stop_date_time;
   else if discharge &amp;gt;= 7 then new_stop_date_time= stop_date_time;
end;
else new_stop_date_time= intnx('dtday', start_date_time, 7);
format new_stop_date_time DATETIME16.;
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 May 2020 16:33:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-add-days/m-p/648619#M194337</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-05-18T16:33:17Z</dc:date>
    </item>
    <item>
      <title>Re: date add days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-add-days/m-p/648626#M194340</link>
      <description>&lt;P&gt;Start by reading the log and fixing the syntax errors. Your code misses a semicolon.&lt;/P&gt;</description>
      <pubDate>Mon, 18 May 2020 16:58:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-add-days/m-p/648626#M194340</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-18T16:58:14Z</dc:date>
    </item>
  </channel>
</rss>

