<?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 date and time computations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/date-and-time-computations/m-p/742536#M232294</link>
    <description>&lt;P&gt;I need to compute a date-time variable given the number of seconds (dstarttim, below) from 01.01.1960 (I think, but let's say it's true) and then do a comparison of that date with another date. Fortunately Cody has a chapter on date arithmetic in his book but unfortunately it doesn't include time. But from it i got the intnx function.&lt;/P&gt;
&lt;P&gt;I wrote&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ivuedone=intx('second','01jan60:00:00:00'dt,dstarttim,'same');

put ivuedone datetime18;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I get errors: iwuedone in line 1 is marked as an error and line 2 likewise not liked. I'm doing something wrong; what is it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's part A, now part B. I want to say&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if (iwuedone lt '15mar2020' d9) then precovid=1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Will that work?&lt;/P&gt;
&lt;P&gt;Alternatively, how would this be written:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;If (dstarttime le 15mar2020 in seconds) then precovid=1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Gene Maguin&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;P&gt;&amp;nbsp;&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;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 19 May 2021 23:59:41 GMT</pubDate>
    <dc:creator>emaguin</dc:creator>
    <dc:date>2021-05-19T23:59:41Z</dc:date>
    <item>
      <title>date and time computations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-and-time-computations/m-p/742536#M232294</link>
      <description>&lt;P&gt;I need to compute a date-time variable given the number of seconds (dstarttim, below) from 01.01.1960 (I think, but let's say it's true) and then do a comparison of that date with another date. Fortunately Cody has a chapter on date arithmetic in his book but unfortunately it doesn't include time. But from it i got the intnx function.&lt;/P&gt;
&lt;P&gt;I wrote&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ivuedone=intx('second','01jan60:00:00:00'dt,dstarttim,'same');

put ivuedone datetime18;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I get errors: iwuedone in line 1 is marked as an error and line 2 likewise not liked. I'm doing something wrong; what is it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's part A, now part B. I want to say&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if (iwuedone lt '15mar2020' d9) then precovid=1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Will that work?&lt;/P&gt;
&lt;P&gt;Alternatively, how would this be written:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;If (dstarttime le 15mar2020 in seconds) then precovid=1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Gene Maguin&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;P&gt;&amp;nbsp;&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;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 May 2021 23:59:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-and-time-computations/m-p/742536#M232294</guid>
      <dc:creator>emaguin</dc:creator>
      <dc:date>2021-05-19T23:59:41Z</dc:date>
    </item>
    <item>
      <title>Re: date and time computations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-and-time-computations/m-p/742537#M232295</link>
      <description>&lt;P&gt;FYI - I've formatted your question to make it more legible. Please try and use the code blocks in future posts and space out your text.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a great, but longer and in depth, reference for dates and times in SAS&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 20 May 2021 00:01:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-and-time-computations/m-p/742537#M232295</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-05-20T00:01:59Z</dc:date>
    </item>
    <item>
      <title>Re: date and time computations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-and-time-computations/m-p/742556#M232307</link>
      <description>&lt;P&gt;1. There is no need to use INTNX to create a datetime out of the dstarttim, it's already a DATETIME because that's how SAS stores datetimes. Read the reference from the prior link for more details. Apply a format to the variable to have it display correctly.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format dstarttim datetime22.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;2. Specify a data constant in the format of "DDMONYYYY"d - no 9.&amp;nbsp; Since your variable is a datetime and you're comparing it to a date, you need to use DATEPART to get just the date portion as well.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if (datepart(dtstarttim) lt '15mar2020'd) then precovid=1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;3. If you want a seconds comparison, both need to have a time component.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if (dstarttim lt  dhms('15mar2020'd, 0, 0, 0) ) then precovid=1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/273054"&gt;@emaguin&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I need to compute a date-time variable given the number of seconds (dstarttim, below) from 01.01.1960 (I think, but let's say it's true) and then do a comparison of that date with another date. Fortunately Cody has a chapter on date arithmetic in his book but unfortunately it doesn't include time. But from it i got the intnx function.&lt;/P&gt;
&lt;P&gt;I wrote&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ivuedone=intx('second','01jan60:00:00:00'dt,dstarttim,'same');

put ivuedone datetime18;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I get errors: iwuedone in line 1 is marked as an error and line 2 likewise not liked. I'm doing something wrong; what is it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's part A, now part B. I want to say&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if (iwuedone lt '15mar2020' d9) then precovid=1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Will that work?&lt;/P&gt;
&lt;P&gt;Alternatively, how would this be written:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;If (dstarttime le 15mar2020 in seconds) then precovid=1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Gene Maguin&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;P&gt;&amp;nbsp;&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;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 May 2021 00:44:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-and-time-computations/m-p/742556#M232307</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-05-20T00:44:51Z</dc:date>
    </item>
  </channel>
</rss>

