<?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: How to insert file in the DB table as a BLOB in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-insert-file-in-the-DB-table-as-a-BLOB/m-p/229647#M267957</link>
    <description>&lt;P&gt;Hi Nikhil&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm a bit out of my depth here that why I wrote "believe". So just a few thoughts.&lt;/P&gt;
&lt;P&gt;1. The SAS/Access engine supports loading a SAS table into a data base but there is no SAS variable type which allows you to store a BLOB and there is no support of loading into a BLOB documented.&lt;/P&gt;
&lt;P&gt;2. The pass-through code you've posted and everything I could find on the Internet uses a path - and as this executes on the database server this path or url must be accessible from the database server.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Having said that it appears to be possible to load BLOBs via ODBC but it will impact heavily on performance AND you would have to write this on your own (=without the SAS/Access engine). So: I don't know if it's possible at all but I do know that it won't be easy and certainly something you need to write on your own as it's not supported by SAS.&lt;/P&gt;</description>
    <pubDate>Tue, 13 Oct 2015 07:13:35 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2015-10-13T07:13:35Z</dc:date>
    <item>
      <title>How to insert file in the DB table as a BLOB</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-insert-file-in-the-DB-table-as-a-BLOB/m-p/229055#M267952</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We are tryng to Insert an .CSV file as a Blob object in the Table in MS SQL server.&lt;/P&gt;
&lt;P&gt;A) SAS is installed on the UNIX sever and We are using SQL Passthrough facility to insert the file in the database table.&lt;BR /&gt;B) We are facing an error while doing this task.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;ERROR: CLI prepare error: [SAS/ACCESS][ODBC 20101 driver][Microsoft SQL Server]Cannot bulk load because the file &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "/opt/sasinside/SASDATA/EXPORT_LOGS/TESTEXPORT.csv" could not be opened. Operating system error code 3(failed to retrieve &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; text for this error. Reason: 15105).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems like system is not able to find the path specified (Error code 3?)&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;To insert file as a blob in the Database, is it necessary to store the file in the same server/location? Is there any workaround to do this task?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code Used:&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; connect to sqlsvr as myconn (datasrc="MSSQLDSN" user=WinProfileSSRReader password='xxxxxxxxxxxxxxxxxx');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select * from connection to myconn&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;/P&gt;
&lt;P&gt;DECLARE @file AS VARBINARY(MAX);&lt;BR /&gt;SELECT @file = CAST(bulkcolumn AS VARBINARY(MAX))&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM OPENROWSET(&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BULK&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '/opt/sasinside/SASDATA/EXPORT_LOGS/TESTEXPORT.csv',&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SINGLE_BLOB ) AS x;&lt;/P&gt;
&lt;P&gt;/*insert into WinProfileRefUser.SSR_REPORTS (id,tnuid,FILE)*/&lt;BR /&gt;/*&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; values (NEWID(),'CCCCCC',@file)*/&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; );&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; disconnect from myconn;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in Advance,&lt;BR /&gt;Nikhil&lt;/P&gt;</description>
      <pubDate>Thu, 08 Oct 2015 04:54:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-insert-file-in-the-DB-table-as-a-BLOB/m-p/229055#M267952</guid>
      <dc:creator>nikhil_khanolkar</dc:creator>
      <dc:date>2015-10-08T04:54:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert file in the DB table as a BLOB</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-insert-file-in-the-DB-table-as-a-BLOB/m-p/229057#M267953</link>
      <description>&lt;P&gt;There are a few things wrong with your SQL.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;select * from connection to myconn
     (

DECLARE @file AS VARBINARY(MAX);
SELECT @file = CAST(bulkcolumn AS VARBINARY&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The SELECT... statement is for a query and not for what you're trying to do. Look-up the EXECUTE statement.&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/sqlproc/68053/HTML/default/viewer.htm#n0tpd3yaqvep53n1g8wahav3hgco.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/sqlproc/68053/HTML/default/viewer.htm#n0tpd3yaqvep53n1g8wahav3hgco.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can't have two statements in a single EXECUTE() block. You need either to wrap this into PL/SQL or into multiple EXECUTE() blocks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You're sending statements to the database. Loading happens from there so the external file inclusive path must be as "seen" from the database server.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Not sure about your statements. Googling a bit it looks as if this wouldn't need to be that complicated.&lt;/P&gt;&lt;P&gt;&lt;A href="https://msdn.microsoft.com/en-us/library/a1904w6t(VS.80).aspx" target="_blank"&gt;https://msdn.microsoft.com/en-us/library/a1904w6t(VS.80).aspx&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And last but not least: Why do you want to store a textual file a BLOB and not as CLOB?&lt;/P&gt;</description>
      <pubDate>Thu, 08 Oct 2015 05:57:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-insert-file-in-the-DB-table-as-a-BLOB/m-p/229057#M267953</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-10-08T05:57:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert file in the DB table as a BLOB</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-insert-file-in-the-DB-table-as-a-BLOB/m-p/229540#M267954</link>
      <description>&lt;P&gt;Hi Patrick,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks a lot for your thoughts. You are right, database &amp;nbsp;server does not have access to the File location and there are challeges in providing access beacuse of security concerns. So it would take a while before we have required access in place.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was thinking about the workaround where&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;store .CSV file into the SAS server memory as a binary object variable.&lt;/LI&gt;
&lt;LI&gt;and then stream this object from SAS memory into the SQL table column as a BLOB&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Is this feasible to do in SAS?&lt;/P&gt;
&lt;P&gt;Please share&amp;nbsp;your thoughts/suggestions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance,&lt;/P&gt;
&lt;P&gt;Nikhil&lt;/P&gt;</description>
      <pubDate>Mon, 12 Oct 2015 13:38:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-insert-file-in-the-DB-table-as-a-BLOB/m-p/229540#M267954</guid>
      <dc:creator>nikhil_khanolkar</dc:creator>
      <dc:date>2015-10-12T13:38:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert file in the DB table as a BLOB</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-insert-file-in-the-DB-table-as-a-BLOB/m-p/229600#M267955</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't believe your idea can work for multiple reasons.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Would it be possible to copy your files to a location where SQL Server can read them from (eg. via a SFTP) and then dynamically generate the pass-through SQL code for loading?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Oct 2015 21:47:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-insert-file-in-the-DB-table-as-a-BLOB/m-p/229600#M267955</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-10-12T21:47:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert file in the DB table as a BLOB</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-insert-file-in-the-DB-table-as-a-BLOB/m-p/229630#M267956</link>
      <description>&lt;P&gt;Hi Patrick,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That approach is being considered where in SQL reading a file from the location and then inserting in a table. But that would involve creating a area that is accesible to SQL and SAS. We would take that path if any other approach does not work.&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you&amp;nbsp;please advice reasons why idea discussed wouldn't work? Just for my understanding.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is it because concept of storing a file as a binary object in memory is not native to SAS among other reasons?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Nikhil&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2015 04:01:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-insert-file-in-the-DB-table-as-a-BLOB/m-p/229630#M267956</guid>
      <dc:creator>nikhil_khanolkar</dc:creator>
      <dc:date>2015-10-13T04:01:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert file in the DB table as a BLOB</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-insert-file-in-the-DB-table-as-a-BLOB/m-p/229647#M267957</link>
      <description>&lt;P&gt;Hi Nikhil&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm a bit out of my depth here that why I wrote "believe". So just a few thoughts.&lt;/P&gt;
&lt;P&gt;1. The SAS/Access engine supports loading a SAS table into a data base but there is no SAS variable type which allows you to store a BLOB and there is no support of loading into a BLOB documented.&lt;/P&gt;
&lt;P&gt;2. The pass-through code you've posted and everything I could find on the Internet uses a path - and as this executes on the database server this path or url must be accessible from the database server.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Having said that it appears to be possible to load BLOBs via ODBC but it will impact heavily on performance AND you would have to write this on your own (=without the SAS/Access engine). So: I don't know if it's possible at all but I do know that it won't be easy and certainly something you need to write on your own as it's not supported by SAS.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2015 07:13:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-insert-file-in-the-DB-table-as-a-BLOB/m-p/229647#M267957</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-10-13T07:13:35Z</dc:date>
    </item>
  </channel>
</rss>

