%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
2this 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)
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.