我怎么能在sas中引用一个字母?
%sysfunc(tranwrd(%quote(&string),%quote(T),%quote('Test')));
问题是,当字符串有一个' T'和' TR'两者都转移到“测试”中
答案 0 :(得分:0)
SAS宏变量始终是字符。宏函数的参数总是字符,通常不需要额外的宏宏引用层,如果参数是文字,肯定不会。
你先试试这个吗?
%let string = STACKOVERFLOW;
%let string_tweaked = %sysfunc(tranwrd(&string),T,Test);
%put NOTE: string_tweaked = &string_tweaked;
宏值是否包含嵌入的单引号?
%let string = %str(S%'T%'ACKOVERFLOW);
%let string_tweaked = %qsysfunc(tranwrd(&string,'T','Test'));
%put NOTE: string_tweaked = &string_tweaked;
第二个代码示例类似于以下DATA步骤代码(其范围与MACRO环境的范围不同)。显式引用DATA步骤字符串值,使用双引号("
)或单引号('
)
data _null_;
string = "S'T'ACKOVERFLOW";
string_tweaked = tranwrd(string,"'T'","'Test'");
put "NOTE: " string_tweaked=;
run;