<?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: How to convert 15 Sep 2018 12:00 character to Datetime? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-15-Sep-2018-12-00-character-to-Datetime/m-p/528989#M144460</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  datestring = "15 Sep 2018 12:00";
run;

data want;
set have;
datenum = input(compress(substr(datestring,1,11),' '),date9.);
format datenum yymmddd10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The substr extracts the datepart, compress removes the blanks, input with date9. converts to a SAS date.&lt;/P&gt;</description>
    <pubDate>Tue, 22 Jan 2019 06:52:30 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-01-22T06:52:30Z</dc:date>
    <item>
      <title>How to convert 15 Sep 2018 12:00 character to Datetime?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-15-Sep-2018-12-00-character-to-Datetime/m-p/528962#M144455</link>
      <description>&lt;P&gt;Hi. I am currently trying to convert data that is in:&lt;BR /&gt;15 Sep 2018 12:00:00 Character to Datetime.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have managed to successfully convert Character 15/08/2018 12:00:00 to Datetime but not&amp;nbsp;&lt;SPAN&gt;15 Sep 2018 12:00.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The data was originally in Excel. When i load&amp;nbsp;15/08/2018 12:00 in, i will get numbers such as (Numbers May differ)&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;42541.843148148&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Here is my code:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;data have;
 input exl_dt;
 format date date9.;
 format time timeampm.;
 format dt datetime21.;
 date=int(exl_dt)-21916;
 time=(exl_dt-int(exl_dt))*60*60*24;
 dt=date*24*60*60+time;
cards;
42541.843148148
;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;However, I am reading another excel now but my character date is now:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;15 Sep 2018 12:00&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The same code above will not be able to convert the value to datetime and only produce blank value.&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;data have ;
  datestring = "15 Sep 2018 12:00" ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;How should i handle this?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jan 2019 04:25:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-15-Sep-2018-12-00-character-to-Datetime/m-p/528962#M144455</guid>
      <dc:creator>WorkingMan</dc:creator>
      <dc:date>2019-01-22T04:25:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert 15 Sep 2018 12:00 character to Datetime?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-15-Sep-2018-12-00-character-to-Datetime/m-p/528965#M144456</link>
      <description>&lt;P&gt;I have posted it in the wrong section. Can any moderator move my thread to "Programming" section?&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jan 2019 03:38:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-15-Sep-2018-12-00-character-to-Datetime/m-p/528965#M144456</guid>
      <dc:creator>WorkingMan</dc:creator>
      <dc:date>2019-01-22T03:38:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert 15 Sep 2018 12:00 character to Datetime?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-15-Sep-2018-12-00-character-to-Datetime/m-p/528989#M144460</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  datestring = "15 Sep 2018 12:00";
run;

data want;
set have;
datenum = input(compress(substr(datestring,1,11),' '),date9.);
format datenum yymmddd10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The substr extracts the datepart, compress removes the blanks, input with date9. converts to a SAS date.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jan 2019 06:52:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-15-Sep-2018-12-00-character-to-Datetime/m-p/528989#M144460</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-01-22T06:52:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert 15 Sep 2018 12:00 character to Datetime?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-15-Sep-2018-12-00-character-to-Datetime/m-p/528993#M144461</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/189060"&gt;@WorkingMan&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use the&amp;nbsp;ANYDTDTMw. informat:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_ ;                               
  datestring = "15 Sep 2018 12:00" ;        
  datetime = input (datestring, anydtdtm.) ;&lt;BR /&gt;  /* test */
  put datetime= / datetime=datetime. ;                  
run ;                                       
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You'll see that the step prints:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;datetime=1852632000&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt; datetime=15SEP18:12:00:00&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first is the actual SAS system datetime stored value (the number of seconds since the beginning of 1960) to which the ANYDTDTMw. informat converted datestring; the second is this value formatted by the DATETIMEw. format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best&lt;/P&gt;
&lt;P&gt;Paul D.&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jan 2019 07:26:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-15-Sep-2018-12-00-character-to-Datetime/m-p/528993#M144461</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-01-22T07:26:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert 15 Sep 2018 12:00 character to Datetime?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-15-Sep-2018-12-00-character-to-Datetime/m-p/529219#M144535</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/189060"&gt;@WorkingMan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi. I am currently trying to convert data that is in:&lt;BR /&gt;15 Sep 2018 12:00:00 Character to Datetime.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have managed to successfully convert Character 15/08/2018 12:00:00 to Datetime but not&amp;nbsp;&lt;SPAN&gt;15 Sep 2018 12:00.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The data was originally in Excel. When i load&amp;nbsp;15/08/2018 12:00 in, i will get numbers such as (Numbers May differ)&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;42541.843148148&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Here is my code:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;data have;
 input exl_dt;
 format date date9.;
 format time timeampm.;
 format dt datetime21.;
 date=int(exl_dt)-21916;
 time=(exl_dt-int(exl_dt))*60*60*24;
 dt=date*24*60*60+time;
cards;
42541.843148148
;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;However, I am reading another excel now but my character date is now:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;15 Sep 2018 12:00&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The same code above will not be able to convert the value to datetime and only produce blank value.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;data have ;
  datestring = "15 Sep 2018 12:00" ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;How should i handle this?&lt;/SPAN&gt;&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;If you are actually seeing in your SAS data set then likely the approach you used for reading the data from Excel to SAS is the main culprit. That numeric value of 42541.843148148 likely&amp;nbsp;indicates a number of days since 1/1/1900 and then a fraction of a day as the way Excel stores datetime values. I might suggest going back to the step that read the data from Excel, save the data as CSV after making sure that all of the columns with date or times have the same Excel display set for the column. Then read/import the CSV. If using Proc import set a large value for GUESSINGROWS to have a better chance of proper values. If you will be reading multiple files of the same structure I recommend taking the time to write a proper data step to read a CSV file. Import direct from Excel can only read a few rows of data to set types and user behaviors can complicate your life tremendously if the Excel has manually entered or edited data cells.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jan 2019 18:54:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-15-Sep-2018-12-00-character-to-Datetime/m-p/529219#M144535</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-01-22T18:54:10Z</dc:date>
    </item>
  </channel>
</rss>

