<?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: Convert Character to Date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-Character-to-Date/m-p/475402#M122246</link>
    <description>&lt;P&gt;Your idea of using the anydtdtm informat works:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input indate anydtdtm19.;
format indate dateampm22.;
cards;
Aug 24 2017 12:11PM
Dec  7 2017  2:12PM
May 28 2014  3:55PM
;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;               indate

24AUG2017:12:11:00 PM
07DEC2017:02:12:00 PM
28MAY2014:03:55:00 PM
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;&lt;EM&gt;Edit: increased length of display format from 20 to 22 to get a 4-digit year.&lt;/EM&gt;&lt;/FONT&gt; &lt;/P&gt;</description>
    <pubDate>Wed, 04 Jul 2018 11:00:26 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-07-04T11:00:26Z</dc:date>
    <item>
      <title>Convert Character to Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Character-to-Date/m-p/475386#M122244</link>
      <description>&lt;P&gt;I have a character variable with parameters format=$char19. informat=$char19. that I would would like to convert to datetime. Below are the examples of variables:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Aug 24 2017 12:11PM&lt;/P&gt;&lt;P&gt;Dec&amp;nbsp; 7 2017&amp;nbsp; 2:12PM&lt;/P&gt;&lt;P&gt;May 28 2014&amp;nbsp; 3:55PM&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I believe I only need to use the input function. May I know what informat should I use? I tried these but it seems that I'm getting the wrong value&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;numeric=input('Feb 6 2015 4:51PM',&lt;FONT color="#008080" face="Courier New" size="3"&gt;ANYDTDTM19.&lt;/FONT&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New"&gt;numeric=input('Feb 6 2015 4:51PM',ANYDTTME19&lt;FONT color="#008080" face="Courier New" size="3"&gt;.&lt;/FONT&gt;);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jul 2018 09:39:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Character-to-Date/m-p/475386#M122244</guid>
      <dc:creator>iSAS</dc:creator>
      <dc:date>2018-07-04T09:39:37Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Character to Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Character-to-Date/m-p/475389#M122245</link>
      <description>&lt;P&gt;I am pretty sure that some people go out of their way to make dates as difficult to read as possible.&amp;nbsp; I would do:&lt;/P&gt;
&lt;PRE&gt;data have;
  text="Aug 24 2017 12:11PM"; output;
  text="Dec  7 2017  2:12PM"; output;
run;

data want (drop=tmp_:);
  set have;
  tmp_date=input(cats(substr(text,5,2),substr(text,1,3),substr(text,8,4)),date9.);
  tmp_time=input(strip(substr(text,12,6)),time5.);
  want=dhms(tmp_date,hour(tmp_time),minute(tmp_time),0);
  format want datetime.;
run;&lt;/PRE&gt;
&lt;P&gt;Well, I would probably go back to source and change that into a usable format myself...&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jul 2018 09:55:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Character-to-Date/m-p/475389#M122245</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-07-04T09:55:05Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Character to Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Character-to-Date/m-p/475402#M122246</link>
      <description>&lt;P&gt;Your idea of using the anydtdtm informat works:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input indate anydtdtm19.;
format indate dateampm22.;
cards;
Aug 24 2017 12:11PM
Dec  7 2017  2:12PM
May 28 2014  3:55PM
;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;               indate

24AUG2017:12:11:00 PM
07DEC2017:02:12:00 PM
28MAY2014:03:55:00 PM
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;&lt;EM&gt;Edit: increased length of display format from 20 to 22 to get a 4-digit year.&lt;/EM&gt;&lt;/FONT&gt; &lt;/P&gt;</description>
      <pubDate>Wed, 04 Jul 2018 11:00:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Character-to-Date/m-p/475402#M122246</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-07-04T11:00:26Z</dc:date>
    </item>
  </channel>
</rss>

