I have a very long code which has nested if then else... I want to know what is the best way to code and debug. I am unable to solve the error. the error I am getting is
MPRINT(TREERULE): END;
NOTE: Line generated by the invoked macro "TREERULE".
221 Treatment = '???'; END; END;
221 ! ELSE
----
160
ERROR 160-185: No matching IF-THEN clause.
MPRINT(TREERULE): ELSE DO;
MPRINT(TREERULE): NODENUMBER = 22;
MPRINT(TREERULE): Treatment = '';
MPRINT(TREERULE): END;
but when i go through the code I cant find any missing if then clause
Make the code run outside of a macro before attempting to make it dynamic..
Hint: posting the complete log of a failed step might be really helpful when asking for help. Right now we can only fish in the dark.
Thank you Kurt for the reply. I will try running it without the macro. Since I did not have the time, I actually rewrote the whole code, cut it really short to make it work. But I would like to know how to actually debug since this was just a fix. I am not sure if i can share the code thats why i cut the log.
A public forum is not the place to call for emergencies.
Debugging long macro's is definitely a pain.
It looks like you've turned on the correct options:
options mprint symbolgen mlogic;
This assumes that the macro was running correctly at some point and is no longer running, or are you trying to develop a macro that isn't running?
The best way to search otherwise is what is known as a modified binary search approach. Start at the top and reduce the code to one step at a time. Add back steps in chunks until you get an error and then you can look at that specific chunk.
If you need further help you'll at minimum need to post your code and the full log. Ideally, you'll have isolated the code causing issues using the approach above first, but if not, the whole program and log will be required.
PS. You really shouldn't tag questions as urgent. SAS Support is available if you have a paid license or you should have a SAS consultant on call. We're happy to help but your urgency doesn't equal our urgency, we're volunteers, with our own work and lives. And it isn't fair to others who have take the time to plan their work to have their questions pushed down because of a possible 'urgent' request. Basically, it comes off as really rude and inconsiderate and you're overall less likely to get answers. Oh...and if it's truly urgent and you don't respond to questions promptly then it's clearly not really urgent at all.
Aside from others being upset that you used the word "urgent" in your title, you haven't provide enough info for anyone to help. Post at least 10 lines of code that appear above and below the error (from your log). What you posted doesn't give anyone a clue as to what might have happened.
Art, CEO, AnalystFinder.com
@anonymous11 wrote:
Hi Reeza
... The macro had never run before.
And then it's urgent? Development takes time, looks like someone needs to have that drummed into their head.
Maxim 34: Work in steps. Expecting 500 lines of code to work right from the start is, ahem, not intelligent, and that's very polite.
1) Post code and log messages into a code box using the forum {I} menu icon. The underscore character usually appears where SAS flags the error (though sometimes the error may related to something above not ended correctly such as parentheses, quotes or missing ; )
Your posted line (edited to be readable by removing multiple space characters"
221 Treatment = '???'; END; END;
the second end may have closed the "if then" that you Else is expecting to have open. But we can't be certain as the complete log wasn't posted.
If your 500 lines of macro code do not include a lot of comments you might want to consider breaking it up into smaller pieces. Typically a macro that combines data manipulation and output, such as tables or charts, is a candidate to resolve the manipulation into one macro and the tables and/or graphs into different 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 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.