<?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 Write Base64 data to file directly from SQL server in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Write-Base64-data-to-file-directly-from-SQL-server/m-p/556637#M155073</link>
    <description>&lt;P&gt;I have some data in an SQL server database, some of the data is longer than 32767 characters. I would like to save this data to individual files.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know how to do it in SAS when the data is there&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token comment"&gt;*Write the data to file. Then remove the variable that contains the data but keep the variable that contains the path to the file.;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; _null_&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
    &lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; work&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;fileAttachement&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	&lt;SPAN class="token function"&gt;length&lt;/SPAN&gt; filePathName &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;500&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;

	&lt;SPAN class="token comment"&gt;*Set the file path!;&lt;/SPAN&gt;
	filePathName &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;cats&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"C:\temp\"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token statement"&gt;Filename&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;

	&lt;SPAN class="token statement"&gt;file&lt;/SPAN&gt; dummy filevar&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;filePathName&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	&lt;SPAN class="token comment"&gt;*Convert the data from Base64 to binary. NB! This does not work when the file is larger than 32 767 chars... :-(;&lt;/SPAN&gt;
	body &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;body&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt;BASE64X32767&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	&lt;SPAN class="token keyword"&gt;put&lt;/SPAN&gt; body&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;SPAN class="token comment"&gt;*Print the actual content to the file.;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is that most of the files are too long. So, the question is, how can I write the Base64 data directly to file from the SQL step where I extract the data (using proc sql and "connect to odbc as ...". BTW, one of the variables in the data set contains the actual file name that I want to use.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 07 May 2019 02:24:55 GMT</pubDate>
    <dc:creator>heffo</dc:creator>
    <dc:date>2019-05-07T02:24:55Z</dc:date>
    <item>
      <title>Write Base64 data to file directly from SQL server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Write-Base64-data-to-file-directly-from-SQL-server/m-p/556637#M155073</link>
      <description>&lt;P&gt;I have some data in an SQL server database, some of the data is longer than 32767 characters. I would like to save this data to individual files.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know how to do it in SAS when the data is there&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token comment"&gt;*Write the data to file. Then remove the variable that contains the data but keep the variable that contains the path to the file.;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; _null_&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
    &lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; work&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;fileAttachement&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	&lt;SPAN class="token function"&gt;length&lt;/SPAN&gt; filePathName &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;500&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;

	&lt;SPAN class="token comment"&gt;*Set the file path!;&lt;/SPAN&gt;
	filePathName &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;cats&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"C:\temp\"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token statement"&gt;Filename&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;

	&lt;SPAN class="token statement"&gt;file&lt;/SPAN&gt; dummy filevar&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;filePathName&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	&lt;SPAN class="token comment"&gt;*Convert the data from Base64 to binary. NB! This does not work when the file is larger than 32 767 chars... :-(;&lt;/SPAN&gt;
	body &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;body&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt;BASE64X32767&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	&lt;SPAN class="token keyword"&gt;put&lt;/SPAN&gt; body&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;SPAN class="token comment"&gt;*Print the actual content to the file.;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is that most of the files are too long. So, the question is, how can I write the Base64 data directly to file from the SQL step where I extract the data (using proc sql and "connect to odbc as ...". BTW, one of the variables in the data set contains the actual file name that I want to use.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 02:24:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Write-Base64-data-to-file-directly-from-SQL-server/m-p/556637#M155073</guid>
      <dc:creator>heffo</dc:creator>
      <dc:date>2019-05-07T02:24:55Z</dc:date>
    </item>
    <item>
      <title>Re: Write Base64 data to file directly from SQL server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Write-Base64-data-to-file-directly-from-SQL-server/m-p/556664#M155091</link>
      <description>&lt;P&gt;Why do you think you need to use PROC SQL?&lt;/P&gt;
&lt;P&gt;Just make a libref pointing to your source database system.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname mydb odbc ..... ;
data _null_;
    set mydb.fileAttachement;
    ...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 04:57:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Write-Base64-data-to-file-directly-from-SQL-server/m-p/556664#M155091</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-07T04:57:00Z</dc:date>
    </item>
    <item>
      <title>Re: Write Base64 data to file directly from SQL server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Write-Base64-data-to-file-directly-from-SQL-server/m-p/557331#M155351</link>
      <description>&lt;P&gt;I did try that way, after you told me, but it only reads 32 767 chars. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I found some code that can split a large string into substrings (around 900!) but unfortunately, that does not seem to be working. I suspect that it might be because it is saved in the wrong format (if i get smaller files and use the format&amp;nbsp;$BASE64X32767. it works). So I'm still on page one on this one...&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2019 00:16:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Write-Base64-data-to-file-directly-from-SQL-server/m-p/557331#M155351</guid>
      <dc:creator>heffo</dc:creator>
      <dc:date>2019-05-09T00:16:31Z</dc:date>
    </item>
    <item>
      <title>Re: Write Base64 data to file directly from SQL server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Write-Base64-data-to-file-directly-from-SQL-server/m-p/557332#M155352</link>
      <description>&lt;P&gt;Sounds like the problem is that the fields in your database are longer than SAS allows for character fields.&lt;/P&gt;
&lt;P&gt;So in that case you need to use pass through SQL (or have your DB admin make you a view) that can parse the long fields into multiple shorter fields.&lt;/P&gt;
&lt;P&gt;But even then you could create a ViEW using PROC SQL and then just normal data step/proc step to process the view.&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2019 00:19:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Write-Base64-data-to-file-directly-from-SQL-server/m-p/557332#M155352</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-09T00:19:27Z</dc:date>
    </item>
    <item>
      <title>Re: Write Base64 data to file directly from SQL server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Write-Base64-data-to-file-directly-from-SQL-server/m-p/557337#M155354</link>
      <description>Show how the table (or at least the fields you are pulling) is defined in the database.&lt;BR /&gt;Is it one field? Multiple fields? Are they VARCHAR? CLOB? Something Else?&lt;BR /&gt;What options does the language of the database provide for splitting the values into pieces?  Does SUBSTR() or SUBSTRING() work on those data types?&lt;BR /&gt;</description>
      <pubDate>Thu, 09 May 2019 00:37:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Write-Base64-data-to-file-directly-from-SQL-server/m-p/557337#M155354</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-09T00:37:02Z</dc:date>
    </item>
  </channel>
</rss>

