简体   繁体   中英

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. However, when I try to run the %begin macro, SAS EG immediately tells me the program is finished with no errors. 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. contain? Y or "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

%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.

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.

%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.

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. It happens from time to time and the easiest way to fix is to restart the SAS session.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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