<?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 How to convert character to date in PROC SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-character-to-date-in-PROC-SQL/m-p/250683#M268734</link>
    <description>&lt;P&gt;Is there a way to convert a field stored as a character/string and convert it into a date type field?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The database I'm pulling from has all date fields stored as character data types.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example of how field is stored:&lt;/P&gt;
&lt;P&gt;01/07/2016 17:44:32&amp;nbsp; Need to convert to date type to display as 07JAN2016.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here was my first atttempt&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;,input(substr(createtime,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;) || substr(createtime,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;4&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;) || substr(createtime,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;7&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;4&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;), &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;10.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;) format=Date9&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;.&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; TEST_DT&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;My end result was 30JAN4895 which is not correct =(.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Any help would be greatly appreciated.&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 17 Feb 2016 19:43:24 GMT</pubDate>
    <dc:creator>PhatRam33</dc:creator>
    <dc:date>2016-02-17T19:43:24Z</dc:date>
    <item>
      <title>How to convert character to date in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-character-to-date-in-PROC-SQL/m-p/250683#M268734</link>
      <description>&lt;P&gt;Is there a way to convert a field stored as a character/string and convert it into a date type field?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The database I'm pulling from has all date fields stored as character data types.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example of how field is stored:&lt;/P&gt;
&lt;P&gt;01/07/2016 17:44:32&amp;nbsp; Need to convert to date type to display as 07JAN2016.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here was my first atttempt&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;,input(substr(createtime,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;) || substr(createtime,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;4&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;) || substr(createtime,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;7&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;4&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;), &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;10.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;) format=Date9&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;.&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; TEST_DT&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;My end result was 30JAN4895 which is not correct =(.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Any help would be greatly appreciated.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Feb 2016 19:43:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-character-to-date-in-PROC-SQL/m-p/250683#M268734</guid>
      <dc:creator>PhatRam33</dc:creator>
      <dc:date>2016-02-17T19:43:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert character to date in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-character-to-date-in-PROC-SQL/m-p/250692#M268735</link>
      <description>&lt;P&gt;Try&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;input(createtime, anydtdtm.) as test_dt format=dtdate9.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Feb 2016 20:08:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-character-to-date-in-PROC-SQL/m-p/250692#M268735</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-02-17T20:08:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert character to date in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-character-to-date-in-PROC-SQL/m-p/250703#M268736</link>
      <description>&lt;P&gt;Thank you very much this worked perfectly! I have one follow-up question: If I were to pull for say a specific date range instead of creating another proc sql, would I need to do a similar conversion in my where clause?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, what would the syntax look like?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My syntax is probably totally off.. I was thinking something along these lines in my where clause:&lt;/P&gt;
&lt;P&gt;input(createtime, anydtdtm.) between ('01JAN2016', dtdate9.) and ('31JAN2016', dtdate9.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Feb 2016 20:49:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-character-to-date-in-PROC-SQL/m-p/250703#M268736</guid>
      <dc:creator>PhatRam33</dc:creator>
      <dc:date>2016-02-17T20:49:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert character to date in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-character-to-date-in-PROC-SQL/m-p/250713#M268737</link>
      <description>&lt;P&gt;A where clause to select for a date range would look like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where input(createtime, anydtdtm.) between '01JAN2016:00:00:00'dt and '17FEB2016:23:59:59'dt; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where datepart(input(createtime, anydtdtm.)) between '01JAN2016'd and '17FEB2016'd;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Feb 2016 20:57:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-character-to-date-in-PROC-SQL/m-p/250713#M268737</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-02-17T20:57:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert character to date in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-character-to-date-in-PROC-SQL/m-p/250718#M268738</link>
      <description>&lt;P&gt;Many thanks! Worked like a charm!&lt;/P&gt;</description>
      <pubDate>Wed, 17 Feb 2016 21:02:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-character-to-date-in-PROC-SQL/m-p/250718#M268738</guid>
      <dc:creator>PhatRam33</dc:creator>
      <dc:date>2016-02-17T21:02:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert character to date in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-character-to-date-in-PROC-SQL/m-p/250743#M268739</link>
      <description>&lt;P&gt;It helps to understand how SAS stores dates and datetime values. Dates are numbers of days since 1 Jan 1960. Datetimes are numbers of seconds so confusion between the data you have and how you treat it can get entertaining. The values are simply numerics so date values may be abused in many ways.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So what you did was 1) create a string value of 1072016 then 2) input it as a number which when Formatted with DATE9 yielded the results you showed.&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, 18 Feb 2016 00:18:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-character-to-date-in-PROC-SQL/m-p/250743#M268739</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-02-18T00:18:41Z</dc:date>
    </item>
  </channel>
</rss>

