I've googled this issue but I am perplexed by what could be causing it on my end.
My code is basically structured like this:
%MACRO example(var);
%DO j = 1 %TO 10;
* <insert code that works here>;
%IF &var=var1 %THEN
%DO;
* <insert code that works here>;
%END;
%ELSE %IF &var=var2 %THEN
%DO;
* <insert code that works here>;
%END;
*<insert more code that works here>;
%IF &var=var1 %THEN
%DO;
* <insert code that works here>;
%END;
%ELSE %IF &var=var2 %THEN
%DO;
* <insert code that works here>;
%END;
%END;
%MEND example;
%Example(var1);
It's annoying because I had some previous variation of this macro working before, then I tried to add a chunk of something else and a second parameter which made it stop working.. Now I can't even get it to work with one parameter.
The weird thing is that the first %IF-THEN-ELSE statement works fine, it's the second
%ELSE %IF statement that gives me the error..
Yet, the structure is exactly the same as the first one?
Any ideas?
Looking at your pseudo-code, I doubt we can tell you what is wrong. We would need to see the actual code in order to be able to spot the error. Better yet, show us the ACTUAL log from your code, formatted properly so we can read it by clicking on the </> icon and pasting the log (as text) into the window that appears. Do no strip out parts of the log. We need to see the code in the log and the warnings and error messages.
Looking at your pseudo-code, I doubt we can tell you what is wrong. We would need to see the actual code in order to be able to spot the error. Better yet, show us the ACTUAL log from your code, formatted properly so we can read it by clicking on the </> icon and pasting the log (as text) into the window that appears. Do no strip out parts of the log. We need to see the code in the log and the warnings and error messages.
One thing to be careful of in macros is the style of comment you use. The * <text> ; inside a macro may attempt to execute and things like single quotes ie. * this isn't a good idea; may have interesting results. If the comment is truly a comment not to execute use either the block quote /* <text> */ or the macro quote: %* <text> ; inside macros.
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 16. 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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: