0
votes

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!

2
You cannot run a %IF statement alone, it will not work in open code.. You must embed macro logic like %IF inside of a macro definition and call the macro.Tom
What values to the macro variables have? Your macro will not do anything if both conditions are false.Tom

2 Answers

2
votes

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.

0
votes

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.