<?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: Can SAS import SQL Server TIME columns using the ODBC engine? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Can-SAS-import-SQL-Server-TIME-columns-using-the-ODBC-engine/m-p/556314#M154975</link>
    <description>Is it time0 or time7 or both that generate the error?
If time7, do you need nanosecond times?</description>
    <pubDate>Mon, 06 May 2019 00:07:32 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2019-05-06T00:07:32Z</dc:date>
    <item>
      <title>Can SAS import SQL Server TIME columns using the ODBC engine?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-SAS-import-SQL-Server-TIME-columns-using-the-ODBC-engine/m-p/556307#M154973</link>
      <description>&lt;P&gt;&lt;STRONG&gt;tl;dr:&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm getting this error when trying to import SQL Server TIME(0) columns:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;ERROR: CLI cursor fetch error: [Microsoft][SQL Server Native Client 10.0]Numeric value out of range&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I note this previous post on this topic:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://communities.sas.com/t5/General-SAS-Programming/CLI-cursor-fetch-error-Microsoft-SQL-Server-Native-Client-11-0/m-p/251062/highlight/true#M36005" target="_blank"&gt;https://communities.sas.com/t5/General-SAS-Programming/CLI-cursor-fetch-error-Microsoft-SQL-Server-Native-Client-11-0/m-p/251062/highlight/true#M36005&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Details:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;My environment:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS 9.3&lt;/P&gt;&lt;P&gt;SQL Server 2016&lt;/P&gt;&lt;P&gt;SAS/Access ODBC engine&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've run this in SQL Server Management Studio to create a test table:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DROP TABLE IF EXISTS tmp.deleteme

SELECT CAST(GETDATE() AS DATETIME2(0)) AS [datetime]
      ,CAST(GETDATE() AS DATE)         AS [date]
      ,CAST(GETDATE() AS TIME(0))      AS [time0]
      ,CAST(GETDATE() AS TIME(7))      AS [time7]
  INTO tmp.deleteme&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Here is my SAS libname statement:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;27         %libname_sqlsvr(libref=TMP,server=MYSERVER,port=,database=MYDB,schema=tmp)
=================================================================================
LIBREF:           TMP
CONNECT:          NOPROMPT="Driver={SQL Server Native Client 
10.0};Server=MYSERVER;Database=MYDB;Trusted_Connection=yes;"
INTERNAL OPTIONS: schema=tmp bulkload=yes dbcommit=100000 direct_exe=delete preserve_names=yes
USER OPTIONS:
=================================================================================&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Here are other SAS options (many are irrelevant to this issue but here they are anyway):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* set desired SAS options ;
options sastrace=',,,d' sastraceloc=saslog nostsuffix;
options dbidirectexec;
options msglevel=I;
options fullstimer;
options mprint mrecall;
options compress=binary;
options ls=max;
options nocenter;
options lognumberformat=1;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;When I run this code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1;
   set tmp.deleteme (keep=date:);
run;

proc sql;
   connect using tmp;
   create table test2 as
   select *
   from connection to tmp (
SELECT datetime, date from tmp.deleteme
   );
quit;

data test3;
   set tmp.deleteme (keep=time:);
run;

proc sql;
   connect using tmp;
   create table test4 as
   select *
   from connection to tmp (
SELECT time0, time7 from tmp.deleteme
   );
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;tests 3 &amp;amp; 4 throws the above error message.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If SQL Server stores time values differently than SAS, shouldn't SAS's ODBC engine handle this issue?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I &lt;EM&gt;&lt;U&gt;&lt;STRONG&gt;really&lt;/STRONG&gt;&lt;/U&gt; &lt;/EM&gt;want to store the data in the correct format in SQL Server, i.e. TIME(0) for time columns.&lt;/P&gt;&lt;P&gt;I &lt;EM&gt;&lt;U&gt;&lt;STRONG&gt;really&lt;/STRONG&gt;&lt;/U&gt; &lt;/EM&gt;want to just treat the SQL Server table (or view) like a "native" SAS data set.&amp;nbsp; (My end users will want that too).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One approach I can think of is to 1) create a view in SQL Server that casts the time values to varchar, and 2) create a view in SAS that converts the character strings to SAS time values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But that is 1) messy, 2) won't perform as well, and 3) redundant (?) - shouldn't SAS deal with this???&lt;/P&gt;</description>
      <pubDate>Sun, 05 May 2019 22:20:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-SAS-import-SQL-Server-TIME-columns-using-the-ODBC-engine/m-p/556307#M154973</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-05-05T22:20:56Z</dc:date>
    </item>
    <item>
      <title>Re: Can SAS import SQL Server TIME columns using the ODBC engine?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-SAS-import-SQL-Server-TIME-columns-using-the-ODBC-engine/m-p/556314#M154975</link>
      <description>Is it time0 or time7 or both that generate the error?
If time7, do you need nanosecond times?</description>
      <pubDate>Mon, 06 May 2019 00:07:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-SAS-import-SQL-Server-TIME-columns-using-the-ODBC-engine/m-p/556314#M154975</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-05-06T00:07:32Z</dc:date>
    </item>
    <item>
      <title>Re: Can SAS import SQL Server TIME columns using the ODBC engine?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-SAS-import-SQL-Server-TIME-columns-using-the-ODBC-engine/m-p/556322#M154976</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Is it time0 or time7 or both that generate the error? If time7, do you need nanosecond times?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Both generate the error.&amp;nbsp; time7 was only for testing, to see if it made a difference.&amp;nbsp; My actual data is time0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This works...:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   connect using tmp;
   create view test as
   select datetime, date, input(time,time8.) as time format=time.
   from connection to tmp (
SELECT datetime, date, CAST(time0 AS VARCHAR(8)) AS time FROM tmp.deleteme
   );
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;... but I wish I could only embed the libname in the view somehow.&amp;nbsp; I need the explicit pass through for this to work, and I can't figure out how to embed a libname while using explicit pass through.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(I suppose I could create a view on SQL Server to cast to varchar, then a SAS view that references that SQL Server view.&amp;nbsp; A bit messy though...)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Edit:&lt;/STRONG&gt;&amp;nbsp; That's what I've done.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;On SQL Server:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;Three views with the same derived columns for three similar tables.&amp;nbsp; Excerpt:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;          -- workaround bug in SAS 9.3
         ,episode_end_time_sas =
          CAST(episode_end_time AS VARCHAR(8)) 

         ,episode_start_time_sas =
          CAST(episode_start_time AS VARCHAR(8)) 

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Then a view (about 450 columns) which UNION ALL's the three table views into a single view of the three data assets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Then in SAS:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data workspde.all_flat;
   * set PDV order (keep columns in alphabetical order) ;
   if 0 then set dmt.vwALL_FLAT (drop=episode_end_time_sas episode_start_time_sas);

   set dmt.vwALL_FLAT (drop=episode_end_time episode_start_time);  * &amp;lt;&amp;lt;&amp;lt;&amp;lt; these are the problem columns ;
   episode_end_time     = input(episode_end_time_sas,time.);
   episode_start_time   = input(episode_start_time_sas,time.);

   format episode_end_time episode_start_time time.;
   drop episode_end_time_sas episode_start_time_sas;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If I had to do this often, I could save this as a SAS view in a permanent library somewhere...&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2019 04:26:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-SAS-import-SQL-Server-TIME-columns-using-the-ODBC-engine/m-p/556322#M154976</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-05-06T04:26:51Z</dc:date>
    </item>
    <item>
      <title>Re: Can SAS import SQL Server TIME columns using the ODBC engine?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-SAS-import-SQL-Server-TIME-columns-using-the-ODBC-engine/m-p/556323#M154977</link>
      <description>&lt;P&gt;I also opened a ticket with SAS TS, and have gotten a reply.&amp;nbsp; So I'll answer my own question (with help from SAS TS).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's a bug in SAS 9.3, fixed in SAS 9.4.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So if you've found this via searching communities.sas.com, and are still on SAS 9.3, then you have my commiserations.&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2019 02:01:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-SAS-import-SQL-Server-TIME-columns-using-the-ODBC-engine/m-p/556323#M154977</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-05-06T02:01:23Z</dc:date>
    </item>
    <item>
      <title>Re: Can SAS import SQL Server TIME columns using the ODBC engine?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-SAS-import-SQL-Server-TIME-columns-using-the-ODBC-engine/m-p/556326#M154978</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;If SQL Server stores time values differently than SAS, shouldn't SAS's ODBC engine handle this issue?&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;I think SAS receives whatever is send from the ODBC source, and falls over of the value is illegitimate.&lt;/P&gt;
&lt;P&gt;Same if say a string was send for a number field.&lt;/P&gt;
&lt;P&gt;I am curious what is sent back for SAS to fail.&lt;/P&gt;
&lt;P&gt;Also the driver is probably Microsoft's; each vendor usually provides the driver to their data source.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&amp;gt;if I could only embed the libname in the view somehow.&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;I think proc access does that, but you'd need the native access product. ODBC is not supported by proc access.&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;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>Mon, 06 May 2019 02:21:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-SAS-import-SQL-Server-TIME-columns-using-the-ODBC-engine/m-p/556326#M154978</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-05-06T02:21:08Z</dc:date>
    </item>
    <item>
      <title>Re: Can SAS import SQL Server TIME columns using the ODBC engine?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-SAS-import-SQL-Server-TIME-columns-using-the-ODBC-engine/m-p/556329#M154979</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;&lt;EM&gt;&amp;gt;If SQL Server stores time values differently than SAS, shouldn't SAS's ODBC engine handle this issue?&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;I think SAS receives whatever is send from the ODBC source, and falls over of the value is illegitimate.&lt;/P&gt;&lt;P&gt;Same if say a string was send for a number field.&lt;/P&gt;&lt;P&gt;I am curious what is sent back for SAS to fail.&lt;/P&gt;&lt;P&gt;Also the driver is probably Microsoft's; each vendor usually provides the driver to their data source.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not in R&amp;amp;D so this is just conjecture...&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;I think SAS receives whatever is send from the ODBC source&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sure, I get that SAS is using an ODBC API provided by Microsoft, but IMO the SAS ODBC engine should be able to post-process those results as required before returning the results to SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In any case, IMO broken in SAS 9.3, fixed in SAS 9.4 == bug in SAS 9.3.&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;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2019 02:39:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-SAS-import-SQL-Server-TIME-columns-using-the-ODBC-engine/m-p/556329#M154979</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-05-06T02:39:50Z</dc:date>
    </item>
    <item>
      <title>Re: Can SAS import SQL Server TIME columns using the ODBC engine?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-SAS-import-SQL-Server-TIME-columns-using-the-ODBC-engine/m-p/556333#M154980</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;IMO the SAS ODBC engine should be able to post-process those results as required before returning the results to SAS.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;It could be argued both ways.&lt;/P&gt;
&lt;P&gt;If SAS was hiding data issues, one could complain that they want to know about them.&lt;/P&gt;
&lt;P&gt;An option to alter the default behaviour could make everybody happy.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case though,&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;ERROR: CLI cursor fetch error: [Microsoft][SQL Server Native Client 10.0]Numeric value out of range&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;looks like an ODBC error, so SAS doesn't even get the data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&amp;gt;In any case, IMO broken in SAS 9.3, fixed in SAS 9.4 == bug in SAS 9.3.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;True.&lt;/P&gt;
&lt;P&gt;I wonder what is fixed then, if the error happens with the driver.&lt;/P&gt;
&lt;P&gt;Maybe just updating the driver would be enough?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2019 03:03:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-SAS-import-SQL-Server-TIME-columns-using-the-ODBC-engine/m-p/556333#M154980</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-05-06T03:03:20Z</dc:date>
    </item>
    <item>
      <title>Re: Can SAS import SQL Server TIME columns using the ODBC engine?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-SAS-import-SQL-Server-TIME-columns-using-the-ODBC-engine/m-p/556347#M154988</link>
      <description>&lt;P&gt;The reason this breaks is down to a mismatch between the amount of bytes allocated compared with what is needed. Its not well documented in the Microsoft reference manual how many bytes are needed and in SAS 9.3 there weren't enough allocated. We found how much must be allocated to have this work correctly in SAS 9.4 and its fixed there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://docs.microsoft.com/en-us/sql/relational-databases/native-client-odbc-date-time/data-type-support-for-odbc-date-and-time-improvements?view=sql-server-2017" target="_self"&gt;The details&lt;/A&gt; eventually did get documented.&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2019 10:00:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-SAS-import-SQL-Server-TIME-columns-using-the-ODBC-engine/m-p/556347#M154988</guid>
      <dc:creator>SimonDawson</dc:creator>
      <dc:date>2019-05-06T10:00:54Z</dc:date>
    </item>
  </channel>
</rss>

