Tip: SAS and Base64

Follow

Comments

2 comments

  • Yves Payette

    Is it possible to use your sas macro to decode a base64 blob stored in a MySQL variable into a txt file?

    I have a whole table of blob variable to decode in multiple text files.

    Thanks.

  • Michael Dixon

    Hi Yves, The macro as described will only work with Base64 data in an external file, but with a slight tweak to the decoding routine above you could use the following code as a start:

    data _null_;
    length b64 $ 32767 byte $ 1; /* < -- Increase b64 length to max */
    /* Change INFILE and INPUT statements */
    set mysql.table_with_b64blobs;
    b64=input(blob_var,$base64X32767.);
    b64length=length(blob_var);
    /* The rest is the same */
    putlog "NOTE: Detected Base64 Line Length of " b64length;
    file "D:\Temp\my_decoded_file.png" recfm=F lrecl= 1;
    do i=1 to (b64length/4)*3;
    byte=byte(rank(substr(b64,i, 1)));
    put byte $char1.;
    end;
    run;

    The caveat is that because the max string length that can be manipulated in SAS is 32k, your Base64 blob fields in MySQL have to contain 32k characters or less.

Please sign in to leave a comment.

Powered by Zendesk