在SAS,数据的步骤之外,什么是一个空白宏变量替换字符的最佳方式?

StackOverflow https://stackoverflow.com/questions/521207

  •  22-08-2019
  •  | 
  •  

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

似乎TRANSLATE将是一个很好的功能使用。然而,使用%SYSFUNC使用此功能时,该参数不与引号引起来。你怎么表示空白应该被用作替换?

有帮助吗?

解决方案

有在宏语言没有引号。唯一的报价字符都在使用是&%等来表示文本应该被解释为宏“经营者”。空白是通过%str( )如卡罗莱纳州的交上面所指出的表示。

其他提示

在%STR()(带有括号之间的空白)可用于指示空白此参数。另外要注意与翻译...第二个参数是替换字符...但是在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

您可以使用Perl REG前代替,如:

%put ***%sysfunc(prxchange(s/x/ /, -1, abxcdxxf))***;
/* on log
***ab cd  f***
*/
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top