SAS 宏引用未解析
SAS macro reference not resolved
我的代码中有以随机顺序创建和使用的宏。
显示“%put &pincuk”的 "reference not resolved",以及“&pincuk”的语法错误。当我 运行 代码两次时它工作正常。我猜它发生在 SAS 在创建宏之前到达 &pincuk 时。例如,
data x.fcastukcalc;
do day=&daycountuk + 1 to &daycountkorea
retain fcast &ukdmax;
fcast=(fcast * &pincuk) + fcast;
output;
end;
run;
/* then this, later on */
data _null_;
keep deathsuk inc1 inc2 pinc1 pinc2 pinc;
set x.uk;
inc1=deathsuk - lag1(deathsuk);
pinc1=(inc1 / lag1(deathsuk));
inc2=lag1 (deathsuk) - lag2(deathsuk);
pinc2=(inc2 / lag2(deathsuk));
pinc=(pinc1 + pinc2) / 2;
call symputx('pincuk', pinc);
run;
%put &pincUK;
如果在第一个 运行 通过时,x.uk
不存在,或者只有零行,则永远不会到达 call symputx('pincUK',pinc);
。因此,在代码 运行ning 的 'random' 情况下,让我们更慷慨地说 发展性 情况,您的期望可能已被错误记忆的操作或微妙的状态变化。检查代码中的 %SYMDEL
语句。在大型宏的开发过程中,您可能会提交宏内部的部分内容,并且没有完整的 'simulation' 预期在宏的实际调用期间存在的状态。
启动一个新的 SAS 会话,看看代码问题是否仍然存在,是否可以更直接地重现。
具体来说,您的问题是关于宏符号,通常称为宏变量。 宏本身就是一组 SAS 编程语句的名称。
When SAS compiles program text, two delimiters trigger macro processor activity:
&name
- refers to a macro variable. Replacing Text Strings Using Macro Variables explains how to create a macro variable. The form &name is called a macro variable reference.
%name
- refers to a macro. Generating SAS Code Using Macros explains how to create a macro. The form %name is called a macro call.
The text substitution produced by the macro processor is completed before the program text is compiled and executed. The macro facility uses statements and functions that resemble the statements and functions that you use in the DATA step. An important difference, however, is that macro language elements can enable only text substitution and are not present during program or command execution.
------ 编辑(添加)------
编写具有大量抽象(即宏变量)的代码需要一定程度的纪律和系统设计。 宏必须在调用之前编译,但是它解析的宏变量(即符号)在编译时不需要存在,仅在宏调用(调用)时存在。对于老糊涂的人来说,这个概念就像一个包含太多字段的邮件合并样板。
宏变量可以是局部的(作为宏定义中的参数,或在 %LOCAL
中明确说明,或作为对先前未定义符号的赋值。依赖于 GLOBAL 宏变量应减少到最小值或 none,过度依赖预期存在于调用方作用域中的变量也应如此。对全局变量的依赖应使用 [= 明确说明14=] 在宏源中。
对未声明的 %LOCAL
的赋值可能是一个问题,因为赋值 可能 意外地(意外地)替换了声明的或现有变量的值外部(或调用)作用域,并成为 无法正常工作 问题的原因。良好的纪律是明确 %LOCAL
宏定义中的所有变量 - 宏系统 没有 具有 严格模式 (如在其他语言)报告有问题的宏变量。
我的代码中有以随机顺序创建和使用的宏。
显示“%put &pincuk”的 "reference not resolved",以及“&pincuk”的语法错误。当我 运行 代码两次时它工作正常。我猜它发生在 SAS 在创建宏之前到达 &pincuk 时。例如,
data x.fcastukcalc;
do day=&daycountuk + 1 to &daycountkorea
retain fcast &ukdmax;
fcast=(fcast * &pincuk) + fcast;
output;
end;
run;
/* then this, later on */
data _null_;
keep deathsuk inc1 inc2 pinc1 pinc2 pinc;
set x.uk;
inc1=deathsuk - lag1(deathsuk);
pinc1=(inc1 / lag1(deathsuk));
inc2=lag1 (deathsuk) - lag2(deathsuk);
pinc2=(inc2 / lag2(deathsuk));
pinc=(pinc1 + pinc2) / 2;
call symputx('pincuk', pinc);
run;
%put &pincUK;
如果在第一个 运行 通过时,x.uk
不存在,或者只有零行,则永远不会到达 call symputx('pincUK',pinc);
。因此,在代码 运行ning 的 'random' 情况下,让我们更慷慨地说 发展性 情况,您的期望可能已被错误记忆的操作或微妙的状态变化。检查代码中的 %SYMDEL
语句。在大型宏的开发过程中,您可能会提交宏内部的部分内容,并且没有完整的 'simulation' 预期在宏的实际调用期间存在的状态。
启动一个新的 SAS 会话,看看代码问题是否仍然存在,是否可以更直接地重现。
具体来说,您的问题是关于宏符号,通常称为宏变量。 宏本身就是一组 SAS 编程语句的名称。
When SAS compiles program text, two delimiters trigger macro processor activity:
&name
- refers to a macro variable. Replacing Text Strings Using Macro Variables explains how to create a macro variable. The form &name is called a macro variable reference.
%name
- refers to a macro. Generating SAS Code Using Macros explains how to create a macro. The form %name is called a macro call.
The text substitution produced by the macro processor is completed before the program text is compiled and executed. The macro facility uses statements and functions that resemble the statements and functions that you use in the DATA step. An important difference, however, is that macro language elements can enable only text substitution and are not present during program or command execution.
------ 编辑(添加)------
编写具有大量抽象(即宏变量)的代码需要一定程度的纪律和系统设计。 宏必须在调用之前编译,但是它解析的宏变量(即符号)在编译时不需要存在,仅在宏调用(调用)时存在。对于老糊涂的人来说,这个概念就像一个包含太多字段的邮件合并样板。
宏变量可以是局部的(作为宏定义中的参数,或在 %LOCAL
中明确说明,或作为对先前未定义符号的赋值。依赖于 GLOBAL 宏变量应减少到最小值或 none,过度依赖预期存在于调用方作用域中的变量也应如此。对全局变量的依赖应使用 [= 明确说明14=] 在宏源中。
对未声明的 %LOCAL
的赋值可能是一个问题,因为赋值 可能 意外地(意外地)替换了声明的或现有变量的值外部(或调用)作用域,并成为 无法正常工作 问题的原因。良好的纪律是明确 %LOCAL
宏定义中的所有变量 - 宏系统 没有 具有 严格模式 (如在其他语言)报告有问题的宏变量。