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 (August 2005, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 30 Aug 2005 10:36:55 -0700
Reply-To:     Jack Hamilton <jfh@STANFORDALUMNI.ORG>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Jack Hamilton <jfh@STANFORDALUMNI.ORG>
Subject:      Re: ELSE IF
Comments: To: Venky Chakravarthy <swovcc@HOTMAIL.COM>
In-Reply-To:  <200508301640.j7UGehbN018875@listserv.cc.uga.edu>
Content-Type: text/plain; charset="us-ascii"

> Can you clarify with an example your statement (below) > "provided that the > two sets of code are logically equivalent"?

It's my experience, based on looking at lots of code written by many different people, that we SAS users tend to omit some of the elses in if-then-else constructions, so we end if with something like

if a = 1 then b = 2; else if a = 2 then b = 6; if a = 3 then b = 9;

rather than

if a = 1 then b = 2; else if a = 2 then b = 6; else if a = 3 then b = 9;

Using SELECT automatically provides the equivalent of the second version of the code. In short, the problem is that complex if-then-else blocks are prone to human error, which SAS isn't (and perhaps can't be) smart enough to detect.

> Also, I found that the first select construct below executed > slightly more > than two times faster than the second after repeated tests. I > wonder why?

I wouldn't have predicted the run time difference shown in your SELECT example, but having seen it I'm not surprised by it. The logic does seem different even though the results should be the same.

-- Jack Hamilton Oakland, California

> -----Original Message----- > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On > Behalf Of Venky Chakravarthy > Sent: Tuesday, August 30, 2005 9:41 am > To: SAS-L@LISTSERV.UGA.EDU > Subject: Re: [SAS-L] ELSE IF > > Jack, > > That paper, with examples created using the then state of the > art SAS 6.10 > under Microsoft Windows 3.1 running on a 60 MHz Pentium > Processor with 16MB > of RAM, is still very useful on SAS 9.1.3 under Microsoft Windows XP > running on a 2.39 GHz Pentium 4 CPU processor with 512MB of RAM. > > Can you clarify with an example your statement (below) > "provided that the > two sets of code are logically equivalent"? > > Also, I found that the first select construct below executed > slightly more > than two times faster than the second after repeated tests. I > wonder why? > Perhaps, this is an example of a logically different > construct. The first > instance is comparable to the run time for a similarly > constructed "if x=1 > then y = 999". > > data _null_ ; > do i = 1 to 1e7 ; > select ; > when (i=1) y = 999 ; > otherwise ; > end ; > end ; > run ; > > data _null_ ; > do i = 1 to 1e7 ; > select (i) ; > when (1) y = 999 ; > otherwise ; > end ; > end ; > run ; > > > On Tue, 30 Aug 2005 08:09:46 -0700, Jack Hamilton > <jfh@STANFORDALUMNI.ORG> > wrote: > > >We've been told by SAS that IFF-THEN-ELSE and SELECT produce > exactly the > >same code internally, so I'd be surprised if there's a big efficiency > >difference, provided that the two sets of code are logically > equivalent. I > >agree, though, that SELECT wins the aesthetics race. > > > >See also my (rather old) paper on SELECT at > <http://www.excursive.com/sas/>. > > > > > >-- > >Jack Hamilton > >Oakland, California > > > > > > > > > >> -----Original Message----- > >> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On > >> Behalf Of Venky Chakravarthy > >> Sent: Tuesday, August 30, 2005 8:05 am > >> To: SAS-L@LISTSERV.UGA.EDU > >> Subject: Re: [SAS-L] ELSE IF > >> > >> I agree with the assessment that the SELECT construct is more > >> efficient and > >> definitely more aesthetic. Here is something else to ponder. > >> If one needs > >> so many "IF then else" statements that it provides a stress > >> test to the > >> machine's capability, one would need to reconsider the design > >> of the code. > >> > >> Venky Chakravarthy > >> > >> On Tue, 30 Aug 2005 09:37:38 -0500, Russell D Newhouse > >> <NEWHOUSE_RUSSELL_D@LILLY.COM> wrote: > >> > >> >Of course, there is a difference between how many > >> IF-THEN-ELSE statements > >> >whatever system you are using can handle, and how many > make the code > >> >unreadable by humans. > >> > > >> >If you are finding that you are writing a number of nested > >> IF-THEN-ELSE > >> >statments, you might want to consider using a SELECT statement. > >> > > >> > > >> > > >> > > >> > > >> >Arthur Tabachneck <art297@NETSCAPE.NET> > >> >Sent by: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> > >> >08/30/2005 06:59 AM > >> >Please respond to > >> >Arthur Tabachneck <art297@NETSCAPE.NET> > >> > > >> > > >> >To > >> >SAS-L@LISTSERV.UGA.EDU > >> >cc > >> > > >> >Subject > >> >Re: ELSE IF > >> > > >> > > >> > > >> > > >> > > >> > > >> >Jumbo, > >> > > >> >I awoke this morning to an "out of memory" error resulting > >> from the run > >> >with 1,048,576 if then else statements. > >> > > >> >Art > >> >---------- > >> >On Tue, 30 Aug 2005 06:32:44 -0400, J Shrimps, Jr. > >> ><JumboShrimps@HOTMAIL.COM> wrote: > >> > > >> >>I would hope not. > >> >>This was part of a code review discussion. > >> >>Thanx. > >> >> > >> >>"Arthur Tabachneck" <art297@NETSCAPE.NET> wrote in message > >> >>news:200508300344.j7U3igdr003131@listserv.cc.uga.edu... > >> >>> Jumbo, > >> >>> > >> >>> On a two processor Window's NT, using SAS 9 Enterprise, a > >> program runs > >> >>> with 524,288 if then else statements. I'll let you know, > >> tomorrow, if > >> >my > >> >>> latest run (with 1,048,576 if then else statements) also > >> runs. If it > >> >>> does, as I'm no longer bored, I'll leave it to someone > >> else to see if > >> >>> there really is a limit. > >> >>> > >> >>> However, regardless of whether there is or isn't a > limit, does one > >> >really > >> >>> ever need to write a program with that many if then else > >> statements? > >> >>> > >> >>> Art > >> >>> ------- > >> >>> On Mon, 29 Aug 2005 23:20:12 -0400, Arthur Tabachneck > >> >>> <art297@NETSCAPE.NET> wrote: > >> >>> > >> >>> >Jumbo, > >> >>> > > >> >>> >I was bored tonight, thus attempted to find an answer to your > >> >question. > >> >>> > > >> >>> >----------- > >> >>> >On Mon, 29 Aug 2005 19:59:49 -0400, J Shrimps, Jr. > >> >>> ><JumboShrimps@HOTMAIL.COM> wrote: > >> >>> > > >> >>> >>Is there a limit to the number of else if's within an > >> >>> >>if statment? > >> >


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