%macro a(condition);
%do i = 1 %to %if &condition. %then 2; %else 3;;
%put &i.;
%end;
%mend;
ERROR: There is no matching %IF statement for the %ELSE.
ERROR: A dummy macro will be compiled.
what is the problem?
%macro b(condition);
%do i = 1 %to %sysfunc(ifn(&condition., 2, 3));
%put &i.;
%end;
%mend;
%b(0);
%b(1);
%b(0);
1
2
3
%b(1);
1
2
this seem to work, though.
ERROR: There is no matching %IF statement for the %ELSE.
%IF is in a location in a %DO statement where it is not allowed.
ERROR: A dummy macro will be compiled.
You macro named %A has not been compiled and so cannot be used.
This, however, would work, as now the %IF is in a position where it is recognized. (Your %b is another way to make this work)
%macro a(condition);
%if &condition. %then %let endvalue = 2;
%else %let endvalue=3;
%do i = 1 %to &endvalue;
%put &i.;
%end;
%mend;
%a(0)
%a(1)
ERROR: There is no matching %IF statement for the %ELSE.
%IF is in a location in a %DO statement where it is not allowed.
ERROR: A dummy macro will be compiled.
You macro named %A has not been compiled and so cannot be used.
This, however, would work, as now the %IF is in a position where it is recognized. (Your %b is another way to make this work)
%macro a(condition);
%if &condition. %then %let endvalue = 2;
%else %let endvalue=3;
%do i = 1 %to &endvalue;
%put &i.;
%end;
%mend;
%a(0)
%a(1)
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.