【问题标题】:How to mask all characters in this string in SAS如何在SAS中屏蔽此字符串中的所有字符
【发布时间】:2018-07-05 13:34:21
【问题描述】:

我通过将 case when 语句作为宏变量然后注入另一个宏来参数化一些代码。因此,我需要将字符串转换为全局变量,但我正在努力掩盖所有内容。我的代码的简化版本如下所示:

%macro test();

%let x_var = 

case when var = 'Red' then 1
when var = 'Black***' then 2
when var = 'Deep Purple' then 3
else 4
end as var_sort

;

%global var = %nrbquote(&x_reg.);

%mend;

%test;

...但是,当我收到订单的日志错误时,这无法掩盖所有内容:

ERROR: Invalid symbolic variable name =.
ERROR: Invalid symbolic variable name =.
ERROR: Invalid symbolic variable name '.
ERROR: Invalid symbolic variable name '.
ERROR: Invalid symbolic variable name 1.

有人可以就修复方法提出建议吗?当我试图掩盖特殊字符时,我总是有点困惑,什么是正确的使用方法。

谢谢

【问题讨论】:

  • X_VAR 中没有需要屏蔽的内容。
  • 您创建了一个名为x_var 的宏变量,然后将x_reg 用于全局宏变量?此外,格式可能会有所帮助,而不是 case/if then 逻辑。它更简单,不需要宏。

标签: macros sas


【解决方案1】:

%global 语句用于定义宏变量(符号)。如果要为其分配值,请使用%let 语句。

%global var ;
%let var = %nrbquote(&x_reg.);

如果您想将var 设置为字面意义上的&_rx_reg.,请使用数据步骤。

data _null_;
  call symputx('var','&x_reg.','g');
run;

【讨论】:

    猜你喜欢
    • 2019-11-20
    • 1970-01-01
    • 2017-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多