简体   繁体   English

从SAS中的宏调用宏

[英]Call a macro from a macro in SAS

I am trying to use this macro to run different sections of code. 我正在尝试使用此宏来运行代码的不同部分。 When I select and run the %if statements by themselves, they work. 当我自己选择并运行%if语句时,它们会起作用。 However, when I try to run the %begin macro, SAS EG immediately tells me the program is finished with no errors. 但是,当我尝试运行%begin宏时,SAS EG会立即告诉我程序已完成且没有错误。 However, none of my code runs. 但是,我的代码都没有运行。 This leads me to believe I have a syntax error. 这使我相信我有语法错误。 Does anyone know what is going on? 有人知道发生了什么吗?

%macro begin();
%if &run_NLI_LTC. = "Y" %then %do;
%MDI(1,NonLI_LTC);
%compare(1);
%end;

%if &run_LCE. = "Y" %then %do;
%MDI(2,LCE);
%compare(2);
%end;
%mend begin;
%begin;

Thanks for the help! 谢谢您的帮助!

My guess, with only the information you provide, is that the mistake is here: 仅凭您提供的信息,我的猜测是错误在这里:

%if &run_LCE. = >>"Y"<< %then %do;

What does &run_LCE. &run_LCE.是什么&run_LCE. contain? 包含? Y or "Y" ? Y "Y"还是"Y" Macro variables are not 'character' variables, and so quotation marks are not used, unless they are actually part of the contents of the variable. 宏变量不是“字符”变量,因此除非引号实际上是变量内容的一部分,否则不使用引号。 Normally, I would have only Y in a macro variable, so you need 通常,我在宏变量中只有Y ,因此您需要

%if &run_LCE. = Y %then %do;

You can verify that the %if is failing by turning on the mlogic option ( options mlogic; ) which will print to the log the result of each logical comparison in the macro language. 您可以通过打开mlogic选项( options mlogic; )来验证%if是否失败,该选项将使用宏语言将每个逻辑比较的结果打印到日志中。

There might be something going on with your environment where a macro was not ended properly. 您的环境中可能会发生某些错误,导致宏未正确结束。 I can run the following without error in EG 7.1. 我可以在EG 7.1中运行以下程序而不会出现错误。

%macro printit(s);
%put &s;
%mend;

%macro begin(x);
%if %sysevalf(&x > 0) %then %do;
    %printit(x > 0);
%end;
%if %sysevalf(&x < 0) %then %do;
    %printit(x > 0);
%end;
%if %sysevalf(&x = 0) %then %do;
    %printit(x = 0);
%end;
%mend begin;

%begin(1);

Try reconnecting to SAS (right click the active server, and select "Disconnect") and running the above. 尝试重新连接到SAS(右键单击活动服务器,然后选择“断开连接”),然后运行上面的命令。

If that works, then you may have a macro in your code that is not ended properly. 如果可行,则您的代码中可能包含一个宏,该宏未正确结束。 That is, SAS got in a state where it thinks it is still compiling a macro. 也就是说,SAS认为自己仍在编译宏。 It happens from time to time and the easiest way to fix is to restart the SAS session. 它不时发生,最简单的修复方法是重新启动SAS会话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM