DATA Step, Macro, Functions and more

urgent help for if then else debugging

Reply
New Contributor
Posts: 3

urgent help for if then else debugging

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

Super User
Posts: 10,592

Re: urgent help for if then else debugging

Posted in reply to anonymous11

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
New Contributor
Posts: 3

Re: urgent help for if then else debugging

Posted in reply to KurtBremser

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. 

Esteemed Advisor
Posts: 5,626

Re: urgent help for if then else debugging

Posted in reply to anonymous11

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

PG
Super User
Posts: 24,026

Re: urgent help for if then else debugging

Posted in reply to anonymous11

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. 

 

New Contributor
Posts: 3

Re: urgent help for if then else debugging

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.
Thanks
Super User
Posts: 8,220

Re: urgent help for if then else debugging

[ Edited ]
Posted in reply to anonymous11

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

Super User
Posts: 10,592

Re: urgent help for if then else debugging

Posted in reply to anonymous11

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 13,942

Re: urgent help for if then else debugging

Posted in reply to anonymous11

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.

Ask a Question
Discussion stats
  • 8 replies
  • 237 views
  • 6 likes
  • 6 in conversation