<?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 Need help extracting BLOB image from DB table and embed it on PROC Report in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-help-extracting-BLOB-image-from-DB-table-and-embed-it-on/m-p/954885#M372948</link>
    <description>&lt;P&gt;Hi SAS Community!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is my first time working with image column in SAS EG. Now, I need help in extracting an Image (BLOB Jpeg Image) from the DB table and have it embedded on an HTML report.&lt;/P&gt;
&lt;P&gt;The user must be able to download the image once it's clicked on the HTML Report.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;What I have done so far:&lt;BR /&gt;-Tried to download on unix server and reference the images on the proc report, but users doesn't have access on the unix server path in order to download.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's what I researched, please correct me if I am wrong since I'm really lost right now:&lt;/P&gt;
&lt;P&gt;-The column IDPIC value starts with something like this (sample=FFD8FFE000104A4649460001010000480048) which is in hexadecimal format.&lt;/P&gt;
&lt;P&gt;-I&amp;nbsp;&lt;SPAN&gt;don't need to download the image on my local (Unix server) for me to embed it to HTML.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;-From the hexadecimal format, I need to convert it into RAW binary format first (sample=ÿØÿàJFIFHHÿáExifMM*JR(iZHH&amp;nbsp;ö&amp;nbsp;Ñÿí8Photoshop3.08BIM8BIM%ÔÙ²éìøB~ÿâ)&lt;BR /&gt;before converting it into base-64 (this is the format that can be embedded on PROC Report)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;-SAS EG doesn't have a built in base64 encode function.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Here's my code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;DATA TBL_FOR_PROC_REPORT;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp;SET SOURCE_TBL;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp;length IMG $32767 clean_hex $32767 stable_hex $32767 binary_data $32767 i 8 hex_byte $2;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp;IF NOT MISSING(IDPIC) AND NOT MISSING(REFNO) AND NOT MISSING(SNAME) THEN DO;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;clean_hex = compress(IDPIC, ' ');&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;stable_hex = TRANWRD(clean_hex, '0A'x, '');&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;stable_hex = TRANWRD(stable_hex, '0D'x, '');&amp;nbsp;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;stable_hex = compress(stable_hex, , 'kw');&amp;nbsp;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;binary_data = '';&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;FONT color="#99CC00"&gt;/* This is where the conversion fails */&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DO i = 1 TO LENGTH(stable_hex) BY 2;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;hex_byte = substr(stable_hex, i, 2);&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;binary_data = catx('', binary_data, byte(input(hex_byte, $HEX2.)));&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;END;&amp;nbsp;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;FONT color="#99CC00"&gt;/* This column shows corrupted image on proc report later on */&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;IMG = 'data&amp;amp;colon;image/jpeg;base64,' || PUT(binary_data, $BASE64X32767.);&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp;END;&amp;nbsp;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp;ELSE DO;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;IMG = 'No ID';&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp;END;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp;DROP i hex_byte clean_hex;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;RUN;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your replies would be of great help! Thank you!&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 02 Jan 2025 08:13:08 GMT</pubDate>
    <dc:creator>meatballs12345</dc:creator>
    <dc:date>2025-01-02T08:13:08Z</dc:date>
    <item>
      <title>Need help extracting BLOB image from DB table and embed it on PROC Report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-extracting-BLOB-image-from-DB-table-and-embed-it-on/m-p/954885#M372948</link>
      <description>&lt;P&gt;Hi SAS Community!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is my first time working with image column in SAS EG. Now, I need help in extracting an Image (BLOB Jpeg Image) from the DB table and have it embedded on an HTML report.&lt;/P&gt;
&lt;P&gt;The user must be able to download the image once it's clicked on the HTML Report.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;What I have done so far:&lt;BR /&gt;-Tried to download on unix server and reference the images on the proc report, but users doesn't have access on the unix server path in order to download.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's what I researched, please correct me if I am wrong since I'm really lost right now:&lt;/P&gt;
&lt;P&gt;-The column IDPIC value starts with something like this (sample=FFD8FFE000104A4649460001010000480048) which is in hexadecimal format.&lt;/P&gt;
&lt;P&gt;-I&amp;nbsp;&lt;SPAN&gt;don't need to download the image on my local (Unix server) for me to embed it to HTML.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;-From the hexadecimal format, I need to convert it into RAW binary format first (sample=ÿØÿàJFIFHHÿáExifMM*JR(iZHH&amp;nbsp;ö&amp;nbsp;Ñÿí8Photoshop3.08BIM8BIM%ÔÙ²éìøB~ÿâ)&lt;BR /&gt;before converting it into base-64 (this is the format that can be embedded on PROC Report)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;-SAS EG doesn't have a built in base64 encode function.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Here's my code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;DATA TBL_FOR_PROC_REPORT;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp;SET SOURCE_TBL;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp;length IMG $32767 clean_hex $32767 stable_hex $32767 binary_data $32767 i 8 hex_byte $2;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp;IF NOT MISSING(IDPIC) AND NOT MISSING(REFNO) AND NOT MISSING(SNAME) THEN DO;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;clean_hex = compress(IDPIC, ' ');&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;stable_hex = TRANWRD(clean_hex, '0A'x, '');&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;stable_hex = TRANWRD(stable_hex, '0D'x, '');&amp;nbsp;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;stable_hex = compress(stable_hex, , 'kw');&amp;nbsp;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;binary_data = '';&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;FONT color="#99CC00"&gt;/* This is where the conversion fails */&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DO i = 1 TO LENGTH(stable_hex) BY 2;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;hex_byte = substr(stable_hex, i, 2);&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;binary_data = catx('', binary_data, byte(input(hex_byte, $HEX2.)));&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;END;&amp;nbsp;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;FONT color="#99CC00"&gt;/* This column shows corrupted image on proc report later on */&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;IMG = 'data&amp;amp;colon;image/jpeg;base64,' || PUT(binary_data, $BASE64X32767.);&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp;END;&amp;nbsp;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp;ELSE DO;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;IMG = 'No ID';&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp;END;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;&amp;nbsp; &amp;nbsp;DROP i hex_byte clean_hex;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="courier new,courier" size="2"&gt;RUN;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your replies would be of great help! Thank you!&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jan 2025 08:13:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-extracting-BLOB-image-from-DB-table-and-embed-it-on/m-p/954885#M372948</guid>
      <dc:creator>meatballs12345</dc:creator>
      <dc:date>2025-01-02T08:13:08Z</dc:date>
    </item>
    <item>
      <title>Re: Need help extracting BLOB image from DB table and embed it on PROC Report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-extracting-BLOB-image-from-DB-table-and-embed-it-on/m-p/954993#M372975</link>
      <description>1. I don't see why you need an in-line image for users to be able to download it. If you can save the HTML file somewhere they can see, you can also save an image file there.&lt;BR /&gt;2. If you need an in-line image, see this alternative method &lt;A href="https://blogs.sas.com/content/sgf/2017/04/21/use-sas-send-email-embeds-graph-body-email/" target="_blank"&gt;https://blogs.sas.com/content/sgf/2017/04/21/use-sas-send-email-embeds-graph-body-email/&lt;/A&gt;&lt;BR /&gt;3. If you need a base64 image, I'd first create the image file so you know your blob extraction works. Then you can use the INLINE option of ODS HTML5. &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/odsug/p0hcv8gpxqebnpn1is52we2enltx.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/odsug/p0hcv8gpxqebnpn1is52we2enltx.htm&lt;/A&gt;</description>
      <pubDate>Fri, 03 Jan 2025 05:23:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-extracting-BLOB-image-from-DB-table-and-embed-it-on/m-p/954993#M372975</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2025-01-03T05:23:52Z</dc:date>
    </item>
    <item>
      <title>Re: Need help extracting BLOB image from DB table and embed it on PROC Report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-extracting-BLOB-image-from-DB-table-and-embed-it-on/m-p/954994#M372976</link>
      <description>&lt;P&gt;that's awesome&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jan 2025 07:38:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-extracting-BLOB-image-from-DB-table-and-embed-it-on/m-p/954994#M372976</guid>
      <dc:creator>JMANGUERRA</dc:creator>
      <dc:date>2025-01-03T07:38:51Z</dc:date>
    </item>
    <item>
      <title>Re: Need help extracting BLOB image from DB table and embed it on PROC Report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-extracting-BLOB-image-from-DB-table-and-embed-it-on/m-p/955188#M373053</link>
      <description>&lt;P&gt;Hello, the requirement is to embed the image on the excel report that's supposed to be generated when the "export to excel" link was clicked on the SAS HTML Report.&lt;BR /&gt;Also, if my understanding is correct, does that mean I have to download the image elsewhere first?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2025 06:01:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-extracting-BLOB-image-from-DB-table-and-embed-it-on/m-p/955188#M373053</guid>
      <dc:creator>meatballs12345</dc:creator>
      <dc:date>2025-01-06T06:01:54Z</dc:date>
    </item>
  </channel>
</rss>

