BookmarkSubscribeRSS Feed
Calcite | Level 5

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


NOTE: Line generated by the invoked macro "TREERULE".
221                                                            Treatment = '???';                                                     END;                                                 END;
221 !                                             ELSE
ERROR 160-185: No matching IF-THEN clause.

MPRINT(TREERULE):   Treatment = '';


but when i go through the code I cant find any missing if then clause

Super User

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.

Calcite | Level 5

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. 

Opal | Level 21

A public forum is not the place to call for emergencies.

Super User

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. 


Calcite | Level 5
Hi Reeza
Thanks for your reply. The macro had never run before. It was a 500 line code. it would be hard for anyone to go through it and I wasnt sure if I could post the code thats why I asked for some direction.
Apologies if you felt I was rude and I really appreciate you replying on the weekend. yes it was urgent and that's why I just recoded the whole thing. Not sure how will it push down others questions but that was the only way o convey my sense of urgency. again no intention if being inconsiderate.
Opal | Level 21

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,

Super User

@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.

Super User

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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 6 in conversation