Hi SAS Community!
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.
The user must be able to download the image once it's clicked on the HTML Report.
What I have done so far: -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.
Here's what I researched, please correct me if I am wrong since I'm really lost right now:
-The column IDPIC value starts with something like this (sample=FFD8FFE000104A4649460001010000480048) which is in hexadecimal format.
-I don't need to download the image on my local (Unix server) for me to embed it to HTML.
-From the hexadecimal format, I need to convert it into RAW binary format first (sample=ÿØÿàJFIFHHÿáExifMM*JR(iZHH ö Ñÿí8Photoshop3.08BIM8BIM%ÔÙ²éìøB~ÿâ) before converting it into base-64 (this is the format that can be embedded on PROC Report)
-SAS EG doesn't have a built in base64 encode function.
Here's my code:
DATA TBL_FOR_PROC_REPORT;
SET SOURCE_TBL;
length IMG $32767 clean_hex $32767 stable_hex $32767 binary_data $32767 i 8 hex_byte $2;
IF NOT MISSING(IDPIC) AND NOT MISSING(REFNO) AND NOT MISSING(SNAME) THEN DO;
clean_hex = compress(IDPIC, ' ');
stable_hex = TRANWRD(clean_hex, '0A'x, '');
stable_hex = TRANWRD(stable_hex, '0D'x, '');
stable_hex = compress(stable_hex, , 'kw');
binary_data = '';
/* This is where the conversion fails */
DO i = 1 TO LENGTH(stable_hex) BY 2;
hex_byte = substr(stable_hex, i, 2);
binary_data = catx('', binary_data, byte(input(hex_byte, $HEX2.)));
END;
/* This column shows corrupted image on proc report later on */
IMG = 'data:image/jpeg;base64,' || PUT(binary_data, $BASE64X32767.);
END;
ELSE DO;
IMG = 'No ID';
END;
DROP i hex_byte clean_hex;
RUN;
Your replies would be of great help! Thank you! 😊
... View more