为什么我的宏变量不能解析? [英] Why won't my macro variable resolve?
问题描述
我有一个宏变量 &myvar
,但是当我尝试将它放入数据步骤变量时它无法解析.为什么不行,我该怎么做才能解决这个问题?
I have a macro variable, &myvar
, but it won't resolve when I try to put it in a data step variable. Why won't it, and what can I do to fix this?
%let myvar=Hello, world;
data _null_;
x='&myvar.';
put x=;
run;
推荐答案
SAS 中的宏变量在单引号中时无法解析,'&myvar'
.它们需要用双引号括起来,"&myvar"
,以便正确解析.
Macro variables in SAS won't resolve when they are in single quotes, '&myvar'
. They need to be in double quotes, "&myvar"
, in order to resolve properly.
如果您需要单引号和解析的宏变量,您有几个选择,但最简单的是:
If you need to have single quotes and a resolved macro variable, you have a few options, but the simplest is:
%str(%'&myvar.%')
%str
中的 %'
将单独在文本字符串中放置一个单引号字符(或撇号),而不会导致它被引用.
The %'
inside of %str
will place a single quote character (or apostrophe) in the text string by itself without causing it to be quoted.
data _null_;
x="%str(%'&myvar.%')";
put x=;
run;
或
%let myvar2 = %str(%'&myvar.%');
这篇关于为什么我的宏变量不能解析?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!