SAS Macro quoting issues -
i trying perform operations on binary data saved macro variable. datastep below saves data macro variable without issues:
data _null_; infile datalines truncover ; attrib x length=$300 informat=$300. format=$300.; input x $300.; put x=; call symput ('str',cats(x)); datalines4; ‰png > ihdr ) ) ëŠz srgb ®Î=é gama ±^üa phys ;à ;ÃÇo¨d zidat8oåŒ[ À½ÿ¥Ó¼”Ö5dˆ_v@aw|+¸anŠ‡;6<ÞórÆÒÈefõu/'“#f™Ù÷&É|&t"<ß}4¯à6†Ë-Œ_È(%<É'™ènß%)˜Î{- iend®b`‚ ;;;; run;
when try , use contents of macro variable in way, combinations of reserved characters making impossible work with. following reserved characters in value, , not matched:
&%'"()
i've tried every combination of macro quoting functions can think of , can't value print using %put()
:
%put %nrbquote(&str);
results in:
symbolgen: macro variable str resolves ‰png > ihdr ) ) ëŠz srgb ®Î=é gama ±^üa phys ;à ;ÃÇo¨d zidat8oåŒ[ À½ÿ¥Ó¼”Ö5dˆ_v@aw|+¸anŠ‡;6<ÞórÆÒÈefõu/'“#f™Ù÷&É|&t"<ß}4¯à6†Ë-Œ_È(%<É'™ènß%)˜Î{- iend®b`‚ error: value É not valid sas name. error: sas macro facility has encountered i/o error. canceling submitted statements. note: sas system stopped processing due receiving cancel request.
ultimately, i'd convert these values base64 encoding using following statement (i've pre-calculated length of base64 format ease-of-debugging):
%let base64_string = %sysfunc(putc(%nrbquote(&str),$base64x244.));
you can use %superq()
quote macro variable without having first expand it. note takes name of macro variable , not value argument.
%let base64_string = %sysfunc(putc(%superq(str),$base64x244.));
but why not transformation in data step , avoid macro quoting issues?
Comments
Post a Comment