SAS Macro quoting issues

主宰稳场 提交于 2019-12-14 02:35:24

问题


I am trying to perform operations on binary data saved into a macro variable. The datastep below successfully saves the data into the macro variable without any 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 I try and use the contents of the macro variable in any way, the combinations of reserved characters are making it impossible to work with. The following reserved characters are in the value, and are not matched:

&%'"()

I've tried every combination of macro quoting functions I can think of and I can't even get the value to print using a %put():

%put %nrbquote(&str);

Results in:

SYMBOLGEN:  Macro variable STR resolves to ‰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: The value É is not a valid SAS name.
ERROR: The SAS Macro Facility has encountered an I/O error.  Canceling submitted statements.

NOTE: The SAS System stopped processing due to receiving a CANCEL request.

Ultimately, what I'd like to do is convert these values to a base64 encoding using the following statement (I've pre-calculated the length of the base64 format for ease-of-debugging):

%let base64_string = %sysfunc(putc(%nrbquote(&str),$base64x244.));

回答1:


You can use %SUPERQ() to quote a macro variable without having to first expand it. Note that it takes the name of macro variable and not the value as its argument.

%let base64_string = %sysfunc(putc(%superq(str),$base64x244.));

But why not just do the transformation in a DATA STEP and avoid the macro quoting issues?



来源:https://stackoverflow.com/questions/34822255/sas-macro-quoting-issues

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!