SAS Enterprise Guide

Desktop productivity for business analysts and programmers
BookmarkSubscribeRSS Feed
Klapatauskas
Calcite | Level 5

I am using a PROC SQL in SAS EG connected to a Hive. I am trying to take this 

 

 

Substring(CLM.etl_file_name,(length(substring_index(CLM.etl_file_name,'_',1))-7),8)


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 

 

 

 

CAST(Substring(CLM.etl_file_name,(length(substring_index(CLM.etl_file_name,'_',1))-7),8)as DATE) as myETLdate

but it returns every value as a decimal point or period...call it a dot


If I use Convert

 

 

 

Convert(Substring(CLM.etl_file_name,(length(substring_index(CLM.etl_file_name,'_',1))-7),8), DATE)


I get this message back

 

 

CLI prepare error: [Hortonworks][Hardy] (80) Syntax or semantic analysis error thrown in server while executing query. Error
message from server: Error while compiling statement: FAILED: ParseException line 1:126 cannot recognize input near 'DATE'
2 The SAS System 07:51 Friday, December 27, 2019

')' 'as' in expression specification

 

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.

2 REPLIES 2
ballardw
Super User

Please provide an example of the variable. We have no clue if what you are attempting is appropriate.

 

You may also want to provide an example of how you are connecting to the Hive as others may have some ideas.

 

And lastly do you have an example of passing a date that does not involve any variables that works? If so show that.

Patrick
Opal | Level 21

Looking at the code you've posted I assume you're using explicit pass-through SQL.

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.

 

You haven't posted a sample filename. Based on your code I assume it looks something like: 
someChars-20191228_moreChars

 

Looking into what you've posted I believe you've got two issues here:

1. You're extracting the date string part of the file name

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

 

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.

substr(substring_index(CLM.etl_file_name,'_',1),-10) as date_string

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. 

 

 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 3756 views
  • 0 likes
  • 3 in conversation