%MACRO validate;
%if &A = 0 %then %do;
%createtable;
%end;
%else %do;
%if &B = 0 %then %do;
%createtable;
%end;
%else %do;
%don't create table;
%end;
%end;
%Mend validate;
Does this code work?
%if &A = 0 then &B = 0, so always create table
But it %if &A <> 0, &B can be 0 (and we want it to create table) or it can be <> 0 and we don't want it to create table.
Because &A = &B + &C
Am I missing any %end or %else do?
It seems to me the problem was overcomplicated. If &A= &B+&C and you need the table only when &A=0, then there is no need for &B= condition.
I would simplify it like:
%MACRO validate;
%if &A = 0 %then %do;
%createtable;
%end;
%else %do;
%put NOTE: Condition is not true, table is not created;
%return;
%end;
%Mend validate;
Definitely a problem. While unbalanced single quotes can create problems, this is a call to the macro DON
%don
The simplest version of this macro might be:
%if &A=0 or &B=0 %then %createtable;
This line is a problem.
%don't create table;
Hopefully that is not in your actual code because it could cause your macro to emit unbalance single quotes which will "eat" a lot of code until it finds a closing quote.
You can test both A and B.
%if (&A=0) or (&B=0) %then %do;
* code to create table ;
%end;
Or perhaps test B and C?
%if (&B=0) or (&B=-&C) %then %do;
* code to create table ;
%end;
And if A or B might not be integers (1.5 for instance) then use %SYSEVALF().
%if %sysevalf( (&A=0) or (&B=0) ) %then %do;
* code to create table ;
%end;
This code can't work because
don't
is not a valid name for a macro. Only letters, digits and underscores can be part of a macro name.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.