LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (October 1996, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Mon, 14 Oct 1996 15:34:12 -0700
Reply-To:   Chris B Long <Chris_B_Long@SANDWICH.PFIZER.COM>
Sender:   "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:   Chris B Long <Chris_B_Long@SANDWICH.PFIZER.COM>
Organization:   Pfizer Central Research, Sandwich, Kent, UK
Subject:   Re: 'Proper' use of IF-THEN-ELSE (was IF-THEN-ELSEs in a DATA step)

On Wed, 9 Oct 1996, Don Stanley <don_stanley@IBM.NET> wrote:

>Its a well accepted and clearly defined and taught axiom of computer >programming in virtually any language that IF an ELSE is available THEN >you use it. I find that the syntax without an else is confusing, and its >impact on efficiency can be enormous .... >I've always been of the opinion that omitting the else is similar to >using goto's. There are ALMOST always good reasons for not doing it.

There have been a few replies to my original post concurring with Don's point above. I simply don't agree that the syntax is confusing where ELSE isn't used - to me, because nesting is only *necessary* in certain cases where the conditions *aren't* mutually-exclusive, the use of nesting when the conditions *are* mutually-exclusive is misleading! (I think to myself 'doesn't the programmer realise those conditions are mutually-exclusive?'). For example, in: if x=1 then do; <action 1> end; else if x=2 then do; <action 2> end; one would summarise the conditions necessary for Action 2 happening as 'action 2 only happens when (x is not 1) and (x is 2)'. The redundancy in this summary is what I think makes this construct logically inferior to sequential IFs.

However, I have already agreed that this is largely a question of personal taste, and of course I agreed in the original post that there are efficiency gains to be had in the wise use of nested IFs.

I think the uses of nesting and goto are quite different cases - the impact on a program of using/not using nesting is largely limited to efficiency, whereas using goto directly and drastically affects the program flow, undermining any attempt to build structure into a program, and is therefore much more dangerous.


Back to: Top of message | Previous page | Main SAS-L page