<?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: Formatting string values to datetime issue in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Formatting-string-values-to-datetime-issue/m-p/488634#M127391</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30435"&gt;@lydiawawa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a string variable with the following type of value:&lt;/P&gt;
&lt;P&gt;04-27-2018 09:41:50:815&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code&amp;nbsp; that I used to format the variable to datetime is as of the following:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
   set test;
   date1 = input(date,anydtdtm30.);
   format date1 datetime30.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Instead of converting values to date and time, the returned values are all blank.&lt;/P&gt;
&lt;P&gt;Does anyone know where is the issue is?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&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;Not actually surprised. That last&amp;nbsp;colon really should be a decimal to indicate fractional seconds.&lt;/P&gt;
&lt;P&gt;If you don't NEED the fractional seconds:&lt;/P&gt;
&lt;PRE&gt;data example;
  str='04-27-2018 09:41:50:815';
  dt = input(substr(str,1,19),anydtdtm.);
  format dt datetime.;
run;&lt;/PRE&gt;</description>
    <pubDate>Tue, 21 Aug 2018 20:41:07 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-08-21T20:41:07Z</dc:date>
    <item>
      <title>Formatting string values to datetime issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-string-values-to-datetime-issue/m-p/488621#M127386</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a string variable with the following type of value:&lt;/P&gt;&lt;P&gt;04-27-2018 09:41:50:815&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code&amp;nbsp; that I used to format the variable to datetime is as of the following:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
   set test;
   date1 = input(date,anydtdtm30.);
   format date1 datetime30.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Instead of converting values to date and time, the returned values are all blank.&lt;/P&gt;&lt;P&gt;Does anyone know where is the issue is?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 15:11:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-string-values-to-datetime-issue/m-p/488621#M127386</guid>
      <dc:creator>lydiawawa</dc:creator>
      <dc:date>2018-08-21T15:11:45Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting string values to datetime issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-string-values-to-datetime-issue/m-p/488624#M127387</link>
      <description>&lt;P&gt;Instead of letting the any.... informat make guesses, I'd dissect the string into the time and date part, input those separately with the fitting informats, and then build the datetime by doing&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;datetime = dhms(date,0,0,time);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 15:16:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-string-values-to-datetime-issue/m-p/488624#M127387</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-08-21T15:16:05Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting string values to datetime issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-string-values-to-datetime-issue/m-p/488629#M127388</link>
      <description>&lt;P&gt;I agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;, along those lines&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data w;
date='04-27-2018 09:41:50:815';
date_extract=input(substr(date,1,10),mmddyy10.);
time_extract=input(substr(date,11),time.);
new_date_time=dhms(date_extract,0,0,0)+time_extract;*combine date and time extract;
format new_date_time datetime30.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Aug 2018 15:30:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-string-values-to-datetime-issue/m-p/488629#M127388</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-21T15:30:22Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting string values to datetime issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-string-values-to-datetime-issue/m-p/488634#M127391</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30435"&gt;@lydiawawa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a string variable with the following type of value:&lt;/P&gt;
&lt;P&gt;04-27-2018 09:41:50:815&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code&amp;nbsp; that I used to format the variable to datetime is as of the following:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
   set test;
   date1 = input(date,anydtdtm30.);
   format date1 datetime30.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Instead of converting values to date and time, the returned values are all blank.&lt;/P&gt;
&lt;P&gt;Does anyone know where is the issue is?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&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;Not actually surprised. That last&amp;nbsp;colon really should be a decimal to indicate fractional seconds.&lt;/P&gt;
&lt;P&gt;If you don't NEED the fractional seconds:&lt;/P&gt;
&lt;PRE&gt;data example;
  str='04-27-2018 09:41:50:815';
  dt = input(substr(str,1,19),anydtdtm.);
  format dt datetime.;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Aug 2018 20:41:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-string-values-to-datetime-issue/m-p/488634#M127391</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-21T20:41:07Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting string values to datetime issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-string-values-to-datetime-issue/m-p/488659#M127396</link>
      <description>&lt;P&gt;You can ignore the milliseconds if not required. You can use&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;approach with some other functions,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data test;
str="04-27-2018 09:41:50:815";
DATETIME=DHMS( input(scan(str,1," "),mmddyy10.),     /* Date */
			   input(scan(scan(str,2," "),1,':'),2.),/* Hour */
			   input(scan(scan(str,2," "),2,':'),2.),/* Min  */
			   input(scan(scan(str,2," "),3,':'),2.) /* Sec  */
			  );
format datetime datetime26.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Aug 2018 18:28:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-string-values-to-datetime-issue/m-p/488659#M127396</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-08-21T18:28:12Z</dc:date>
    </item>
  </channel>
</rss>

