<?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 time computation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Date-time-computation/m-p/757984#M239295</link>
    <description>I would use Informat AnydtdtmN where N is the length of the characters that comprise the date time value. You can use AnydtdtmN as part of an INPUT statement or you can use the Input function after you've successfully read in the character data.&lt;BR /&gt;&lt;BR /&gt;Jim</description>
    <pubDate>Thu, 29 Jul 2021 03:20:43 GMT</pubDate>
    <dc:creator>jimbarbour</dc:creator>
    <dc:date>2021-07-29T03:20:43Z</dc:date>
    <item>
      <title>Date time computation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-time-computation/m-p/757983#M239294</link>
      <description>&lt;P&gt;I wish to compute the difference between the following two timepoints, that is Time2-Time2. But the time are characters, that is Char $16. I was expecting it to be Datetime. Anydtdtm40 but they are not. Please can you show me how to convert but Time1 and Time2 from Char $16 to&amp;nbsp;Datetime. Anydtdtm40 and perform the subtraction.&amp;nbsp;&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV align="center"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="430"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="161.625px" height="30px"&gt;Time1&lt;/TD&gt;
&lt;TD width="200.475px" height="30px"&gt;Time2&lt;/TD&gt;
&lt;TD width="66.9px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="161.625px" height="30px"&gt;1/3/18 1:30 PM&lt;/TD&gt;
&lt;TD width="200.475px" height="30px"&gt;.&lt;/TD&gt;
&lt;TD width="66.9px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="161.625px" height="30px"&gt;.&lt;/TD&gt;
&lt;TD width="200.475px" height="30px"&gt;.&lt;/TD&gt;
&lt;TD width="66.9px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="161.625px" height="30px"&gt;1/15/18 10:05 AM&lt;/TD&gt;
&lt;TD width="200.475px" height="30px"&gt;1/16/18 1:31 AM&lt;/TD&gt;
&lt;TD width="66.9px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="161.625px" height="30px"&gt;2/7/18 3:15 PM&lt;/TD&gt;
&lt;TD width="200.475px" height="30px"&gt;.&lt;/TD&gt;
&lt;TD width="66.9px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="161.625px" height="30px"&gt;2/15/18 10:30 PM&lt;/TD&gt;
&lt;TD width="200.475px" height="30px"&gt;2/16/18 11:50 AM&lt;/TD&gt;
&lt;TD width="66.9px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="161.625px" height="30px"&gt;3/5/18 8:20 AM&lt;/TD&gt;
&lt;TD width="200.475px" height="30px"&gt;3/6/18 2:02 AM&lt;/TD&gt;
&lt;TD width="66.9px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="161.625px" height="30px"&gt;3/19/18 9:30 AM&lt;/TD&gt;
&lt;TD width="200.475px" height="30px"&gt;3/19/18 1:55 PM&lt;/TD&gt;
&lt;TD width="66.9px" height="30px"&gt;&amp;nbsp;&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;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 03:03:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-time-computation/m-p/757983#M239294</guid>
      <dc:creator>desireatem</dc:creator>
      <dc:date>2021-07-29T03:03:33Z</dc:date>
    </item>
    <item>
      <title>Re: Date time computation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-time-computation/m-p/757984#M239295</link>
      <description>I would use Informat AnydtdtmN where N is the length of the characters that comprise the date time value. You can use AnydtdtmN as part of an INPUT statement or you can use the Input function after you've successfully read in the character data.&lt;BR /&gt;&lt;BR /&gt;Jim</description>
      <pubDate>Thu, 29 Jul 2021 03:20:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-time-computation/m-p/757984#M239295</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-07-29T03:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: Date time computation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-time-computation/m-p/757985#M239296</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/40563"&gt;@desireatem&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I wish to compute the difference between the following two timepoints, that is Time2-Time2. But the time are characters, that is Char $16. I was expecting it to be Datetime. Anydtdtm40 but they are not. Please can you show me how to convert but Time1 and Time2 from Char $16 to&amp;nbsp;Datetime. Anydtdtm40 and perform the subtraction.&amp;nbsp;&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV align="center"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="430"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="161.625px" height="30px"&gt;Time1&lt;/TD&gt;
&lt;TD width="200.475px" height="30px"&gt;Time2&lt;/TD&gt;
&lt;TD width="66.9px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="161.625px" height="30px"&gt;1/3/18 1:30 PM&lt;/TD&gt;
&lt;TD width="200.475px" height="30px"&gt;.&lt;/TD&gt;
&lt;TD width="66.9px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="161.625px" height="30px"&gt;.&lt;/TD&gt;
&lt;TD width="200.475px" height="30px"&gt;.&lt;/TD&gt;
&lt;TD width="66.9px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="161.625px" height="30px"&gt;1/15/18 10:05 AM&lt;/TD&gt;
&lt;TD width="200.475px" height="30px"&gt;1/16/18 1:31 AM&lt;/TD&gt;
&lt;TD width="66.9px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="161.625px" height="30px"&gt;2/7/18 3:15 PM&lt;/TD&gt;
&lt;TD width="200.475px" height="30px"&gt;.&lt;/TD&gt;
&lt;TD width="66.9px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="161.625px" height="30px"&gt;2/15/18 10:30 PM&lt;/TD&gt;
&lt;TD width="200.475px" height="30px"&gt;2/16/18 11:50 AM&lt;/TD&gt;
&lt;TD width="66.9px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="161.625px" height="30px"&gt;3/5/18 8:20 AM&lt;/TD&gt;
&lt;TD width="200.475px" height="30px"&gt;3/6/18 2:02 AM&lt;/TD&gt;
&lt;TD width="66.9px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="161.625px" height="30px"&gt;3/19/18 9:30 AM&lt;/TD&gt;
&lt;TD width="200.475px" height="30px"&gt;3/19/18 1:55 PM&lt;/TD&gt;
&lt;TD width="66.9px" height="30px"&gt;&amp;nbsp;&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;&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;In a data step create two new variables explicitly using the Anydtdtm informat. An example;&lt;/P&gt;
&lt;PRE&gt;data junk;
   x="1/3/18 1:30 PM";
   y=input(x,anydtdtm32.);
   format y datetime18.;
run;&lt;/PRE&gt;
&lt;P&gt;Depending on how you read the data SAS may not assume that mixes of 1 digit and 2 digit values with slashes and spaces with text like PM are actually date time values.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 03:24:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-time-computation/m-p/757985#M239296</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-07-29T03:24:55Z</dc:date>
    </item>
    <item>
      <title>Re: Date time computation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-time-computation/m-p/758004#M239300</link>
      <description>&lt;P&gt;I really do not like the ANY... informats, as they might happily import something unexpected as a valid value, or misinterpret data because of the locale setting. Mind that several English-speaking countries use a DMY date and not MDY as the US does.&lt;/P&gt;
&lt;P&gt;So be strict:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dlm="," truncover;
input (time1 time2) (:$16.);
datalines;
1/3/18 1:30 PM,.  
.,.  
1/15/18 10:05 AM,1/16/18 1:31 AM  
2/7/18 3:15 PM,.  
2/15/18 10:30 PM,2/16/18 11:50 AM   
3/5/18 8:20 AM,3/6/18 2:02 AM   
3/19/18 9:30 AM,3/19/18 1:55 PM
;

data want;
set have;
array in {*} time1 time2;
array out {*} t1 t2;
format t1 t2 e8601dt19.;
do i = 1 to 2;
  if in{i} ne " "
  then do;
    d = input(scan(in{i},1," "),mmddyy10.);
    t = input(scan(in{i},2," "),time5.);
    if scan(in{i},3," ") = "PM" and t ne 0 then t = t + '12:00't;
    out{i} = dhms(d,0,0,t);
  end;
end;
drop d t i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Any unexpected value will cause a NOTE in the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And I won't elaborate on the intelligence (or lack thereof) of using 2-digit years.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 08:05:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-time-computation/m-p/758004#M239300</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-07-29T08:05:49Z</dc:date>
    </item>
  </channel>
</rss>

