开发者

How to encode base64 in SAS

I need to encode a long string and place in an XML doc. Code sample:

data newData;
 set oldData;
开发者_运维问答 newString=oldString;
 format newString $base64x64.;
run;

Old string looks the same as the new string.. Ideas?


For some reason applying the $base64xw. format to a value doesn't work. Looks like a bug to me. However, using the PUT function to convert a value to base64 works.

data newData;
 set oldData;
 newString=put(oldString,$base64x64.);;
run;


I don't know what version of SAS you're using, but this document says that strings up to 32,767 bytes may be encoded.

Since that's the largest positive 16 bit integer, I'd guess that limit has been around for a while.


Just applying

format newString $base64x64.;

doesn't actually change the value of newString at all. When you say that OldString looks the same as new string, what do you mean? You say that long strings won't encode, so I assume that you're seeing some evidence of encoding in your method.

Note that you've specified an explicit length of 64 on the format, so that the formatted value will take up a field width of 64. So you'll only be able to encode a string of length 48 with that format (BASE64 generates 4 bytes for every 3 in). You say a long string, but how long? As Gilbert mentions, the maximum format length on the BASE64X format is 32767, which means that the maximum output base64 string that you can generate is 32767. It's possible that your input string is just too long, and you'd have to split it somehow.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜