SAS 宏引用问题 [英] SAS Macro quoting issues

查看:41
本文介绍了SAS 宏引用问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对保存在宏变量中的二进制数据执行操作.下面的数据步骤成功地将数据保存到宏变量中,没有任何问题:

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:

&%'"()

我已经尝试了我能想到的所有宏引用函数的组合,但我什至无法使用 %put() 获取要打印的值:

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);

结果:

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.

最终,我想做的是使用以下语句将这些值转换为 base64 编码(为了便于调试,我已经预先计算了 base64 格式的长度):

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.));

推荐答案

您可以使用 %SUPERQ() 引用宏变量,而无需先展开它.请注意,它以宏变量的名称而不是值作为参数.

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.));

但为什么不直接在 DATA STEP 中进行转换并避免宏引用问题?

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

这篇关于SAS 宏引用问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆