Note also that if the encoded string is not an exact multiple of 4 bytes long then you need to append equal signs until it is so that the BASE64 string has the right number of bits to be split back into base256 strings.
Example:
217 data test;
218 x='AB';
219 encode = put(x,$base64x4.);
220 put encode=;
221 run;
encode=QUI=
NOTE: The data set WORK.TEST has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
222
223
224 %let coded=QUI;
225 %let raw_length=%length(&coded);
226 %let actual_length=%eval((&raw_length+3)/4*4);
227 %put &=raw_length &=actual_length ;
RAW_LENGTH=3 ACTUAL_LENGTH=4
228 %put %sysfunc(inputc(&coded,$base64x&raw_length));
229 %put %sysfunc(inputc(&coded,$base64x&actual_length));
230 %put %sysfunc(inputc(&coded===,$base64x&actual_length));
AB
So make sure to figure out the right length to use and to append some equal signs.
... View more