<?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: Converting a String to a Date connected to a Hive in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-String-to-a-Date-connected-to-a-Hive/m-p/614195#M35325</link>
    <description>&lt;P&gt;Looking at the code you've posted I assume you're using explicit pass-through SQL.&lt;/P&gt;
&lt;P&gt;I normally prefer to make such explicit pass-through SQL work outside of SAS (i.e. using HUE) and then copy valid and tested SQL into a SAS pass-through block.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You haven't posted a sample filename. Based on your code I assume it looks something like:&amp;nbsp;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;someChars-20191228_moreChars&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looking into what you've posted I believe you've got two issues here:&lt;/P&gt;
&lt;P&gt;1. You're extracting the date string part of the file name&lt;/P&gt;
&lt;P&gt;2. The date string is not suitable for a direct cast() because Hive requires a date pattern of YYYY-MM-DD for this to work&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest you first get the date string extraction working and only then add the conversion to a date. I can't test it but I believe below could eventually do the job.&lt;/P&gt;
&lt;PRE&gt;substr(substring_index(CLM.etl_file_name,'_',1),-10) as date_string&lt;/PRE&gt;
&lt;P&gt;IF your target table is in SAS then you could also do the conversion from string to SAS date or datetime value on the SAS side.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 29 Dec 2019 02:29:04 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2019-12-29T02:29:04Z</dc:date>
    <item>
      <title>Converting a String to a Date connected to a Hive</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-String-to-a-Date-connected-to-a-Hive/m-p/614126#M35323</link>
      <description>&lt;P&gt;I am using a PROC SQL in SAS EG connected to a Hive. I am trying to take this&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Substring(CLM.etl_file_name,(length(substring_index(CLM.etl_file_name,'_',1))-7),8)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;and turn it in to a date. The original data element is a long string of characters to create a file name. I've tried to use CAST&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;PRE&gt;&lt;CODE class=" language-sas"&gt;CAST(Substring(CLM.etl_file_name,(length(substring_index(CLM.etl_file_name,'_',1))-7),8)as DATE) as myETLdate&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but it returns every value as a decimal point or period...call it a dot&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;If I use Convert&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;PRE&gt;&lt;CODE class=" language-sas"&gt;Convert(Substring(CLM.etl_file_name,(length(substring_index(CLM.etl_file_name,'_',1))-7),8), DATE)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;I get this message back&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;CLI prepare error: [Hortonworks][Hardy] (80) Syntax or semantic analysis error thrown in server while executing query. Error &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;message from server: Error while compiling statement: FAILED: ParseException line 1:126 cannot recognize input near 'DATE' &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;2 The SAS System 07:51 Friday, December 27, 2019&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;')' 'as' in expression specification&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea what will work? I think it might have something to do with the connection to Hive. I've come across one other situation where Hive wanted me to use a different language than what I would normally use with SQL.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Dec 2019 17:53:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-String-to-a-Date-connected-to-a-Hive/m-p/614126#M35323</guid>
      <dc:creator>Klapatauskas</dc:creator>
      <dc:date>2019-12-27T17:53:09Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a String to a Date connected to a Hive</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-String-to-a-Date-connected-to-a-Hive/m-p/614130#M35324</link>
      <description>&lt;P&gt;Please provide an example of the variable. We have no clue if what you are attempting is appropriate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may also want to provide an example of how you are connecting to the Hive as others may have some ideas.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And lastly do you have an example of passing a date that does not involve any variables that works? If so show that.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Dec 2019 18:30:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-String-to-a-Date-connected-to-a-Hive/m-p/614130#M35324</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-12-27T18:30:14Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a String to a Date connected to a Hive</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-String-to-a-Date-connected-to-a-Hive/m-p/614195#M35325</link>
      <description>&lt;P&gt;Looking at the code you've posted I assume you're using explicit pass-through SQL.&lt;/P&gt;
&lt;P&gt;I normally prefer to make such explicit pass-through SQL work outside of SAS (i.e. using HUE) and then copy valid and tested SQL into a SAS pass-through block.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You haven't posted a sample filename. Based on your code I assume it looks something like:&amp;nbsp;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;someChars-20191228_moreChars&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looking into what you've posted I believe you've got two issues here:&lt;/P&gt;
&lt;P&gt;1. You're extracting the date string part of the file name&lt;/P&gt;
&lt;P&gt;2. The date string is not suitable for a direct cast() because Hive requires a date pattern of YYYY-MM-DD for this to work&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest you first get the date string extraction working and only then add the conversion to a date. I can't test it but I believe below could eventually do the job.&lt;/P&gt;
&lt;PRE&gt;substr(substring_index(CLM.etl_file_name,'_',1),-10) as date_string&lt;/PRE&gt;
&lt;P&gt;IF your target table is in SAS then you could also do the conversion from string to SAS date or datetime value on the SAS side.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 29 Dec 2019 02:29:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Converting-a-String-to-a-Date-connected-to-a-Hive/m-p/614195#M35325</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-12-29T02:29:04Z</dc:date>
    </item>
  </channel>
</rss>

