我只是想连接两个引用的宏变量,但似乎没有一个简单的方法。
假设我们有:
%LET VAR1="This is not the greatest song in the world";
%LET VAR2="this is just a tribute.";
%LET TRIBUTE=%SYSFUNC(CATX(%STR( ),&VAR1,&VAR2));
%PUT &TRIBUTE;
我其实想要:
"This is not the greatest song in the world this is just a tribute."
但上面的代码实际上产生:
"This is not the greatest song in the world" "this is just a tribute."
所以我尝试把%QUOTE()
,%BQUOTE
,ETC。大约&VAR1
and %VAR2
希望揭开引号,但我得到了相同的结果。
唯一对我有用的是:
%LET TRIBUTE="%SUBSTR(&VAR1.,2,%LENGTH(&VAR1.)-2) %SUBSTR(&VAR2.,2,%LENGTH(&VAR2.)-2)";
但这很丑陋,而且很快就会变得很长。
难道没有更好的方法吗?
我将解释乔的“真正答案”,即不要在宏变量中存储引号。宏语言中的单引号和双引号与任何其他字符没有什么不同。您应该做的是推迟引入报价,直到您真正需要它们为止。这将产生更干净、更灵活、更易于阅读且无错误的代码。
Code:
请注意,我已经删除了引号并连接字符串,我只是将它们一个接一个地列出:
%LET VAR1=This is not the greatest song in the world;
%LET VAR2=this is just a tribute.;
%LET TRIBUTE=&VAR1 &VAR2;
实施例1
不需要引号来打印出所需的字符串,因为我们使用的是%put
第一个示例中的声明 - 因此我省略了引号:
%PUT &TRIBUTE;
Output :
This is not the greatest song in the world this is just a tribute.
实施例2
需要引号,因为我们现在处于数据步骤领域:
data _null_;
put "&TRIBUTE";
run;
Output :
This is not the greatest song in the world this is just a tribute.
请注意,这两个示例都假设您实际上不想将引号打印到屏幕上。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)