在 SAS 中,在数据步骤之外,将宏变量中的字符替换为空白的最佳方法是什么?

发布于 2024-07-13 10:57:04 字数 162 浏览 4 评论 0原文

在 SAS 中,在数据步骤之外,将宏变量中的字符替换为空白的最佳方法是什么?

看来 TRANSLATE 是一个很好用的函数。 但是,当将 %SYSFUNC 与此函数一起使用时,参数不会用引号引起来。 您如何指示应使用空白作为替换?

In SAS, outside of a data step, what is the best way to replace a character in a macro variable with a blank?

It seems that TRANSLATE would be a good function to use. However when using %SYSFUNC with this function, the parameters are not surrounded with quotes. How do you indicate a blank should be used as replacement?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

请持续率性 2024-07-20 10:57:04

%str( )(括号之间有一个空格)可用于指示此参数的空格。 另外要小心 TRANSLATE...第二个参数是替换字符...但是在 TRANWRD 中它是相反的。

    %macro test ;
     %let original= translate_this_var ;
     %let replaceWithThis= %str( ) ;
     %let findThis= _ ;
     %let translated= %sysfunc(translate(&original, &replaceWithThis, &findThis)) ;
     %put Original: &original ***** TRANSLATEd: &translated ;
    %mend ;
    %test;

    %macro test2 ;
     %let original= translate_this_var ;
     %let replaceWithThis= %str( ) ;
     %let findThis= _ ;
     %let tranwrded= %sysfunc(tranwrd(&original, &findThis, &replaceWithThis)) ;
     %put Original: &original ***** TRANWRDed: &tranwrded ;
    %mend ;
    %test2

The %str( ) (with a blank between the parens) can be used to indicate a blank for this parameter. Also be careful with TRANSLATE...the 2nd param is the replacement char...however in TRANWRD it is reversed.

    %macro test ;
     %let original= translate_this_var ;
     %let replaceWithThis= %str( ) ;
     %let findThis= _ ;
     %let translated= %sysfunc(translate(&original, &replaceWithThis, &findThis)) ;
     %put Original: &original ***** TRANSLATEd: &translated ;
    %mend ;
    %test;

    %macro test2 ;
     %let original= translate_this_var ;
     %let replaceWithThis= %str( ) ;
     %let findThis= _ ;
     %let tranwrded= %sysfunc(tranwrd(&original, &findThis, &replaceWithThis)) ;
     %put Original: &original ***** TRANWRDed: &tranwrded ;
    %mend ;
    %test2
心碎的声音 2024-07-20 10:57:04

宏语言中没有引号。 使用的唯一引号字符是 &% 等,以指示文本应解释为宏“运算符”。 空白由 %str( ) 表示,如上面 Carolina 的帖子中所示。

There are no quotes in macro language. The only quotes characters that are in use are the & , % etc. to indicate that the text should be interpreted as a macro "operator". A blank is represented by %str( ) as indicated above in Carolina's post.

无人问我粥可暖 2024-07-20 10:57:04

您可以使用 perl reg ex 代替,例如:

%put ***%sysfunc(prxchange(s/x/ /, -1, abxcdxxf))***;
/* on log
***ab cd  f***
*/

you can use perl reg ex instead, like:

%put ***%sysfunc(prxchange(s/x/ /, -1, abxcdxxf))***;
/* on log
***ab cd  f***
*/
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文