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 (April 2011, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 14 Apr 2011 03:26:46 -0400
Reply-To:   Søren Lassen <s.lassen@POST.TELE.DK>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Søren Lassen <s.lassen@POST.TELE.DK>
Subject:   Re: SELECT group and IF-THEN/ELSE statements
Comments:   To: Seung-min Baek <760105@HANMAIL.NET>
Content-Type:   text/plain; charset=ISO-8859-1

Seung-min,

A few notes about the SELECT statement:

As someone noted, a final OTHERWISE statement catches whatever is not in the WHEN(...) conditions. You may therefore want to include an OTHERWISE statement... on the other hand you may not - if an unforeseen condition should generate an error message and halt the data step, then you get that "for free" (look mom, no coding) by not having an OTHERWISE statement.

There are actually two forms of the SELECT statement: 1. SELECT(<expression>);WHEN(<value<,value>>)... 2. SELECT;WHEN(<logical expression>)...

The first form can really save you some typing - just note that if you code SAS/SCL, the WHEN() clauses only accept one expression, whereas is the datastep, you can use any (or more than I have tried so far, at least) number of expressions, separated by commas.

Another peculiarity of SAS/SCL is that if you want to have multiple statements after WHEN or OTHERWISE, you do not have to enclose them in DO;...END; - in the datasetp, you must.

I think that the original idea of the SELECT statement in the first form was to set up a jump table, which would take you immediately to the right statement to execute. SAS may do this efficiently if you use fairly simple expressions (e.g. single characters, small integers) in the WHEN() clauses, thus making the SELECT (sometimes and somewhat) faster than repeated IF-THEN-ELSE statements. But I haven't tested this.

Regards, Søren

On Wed, 13 Apr 2011 05:11:28 -0400, Seung-min Baek <760105@HANMAIL.NET> wrote:

>Hello, >Now, I have the question. > >* IF-THEN / ELSE of SAS9.2 : >http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewe r >.htm#a000202239.htm >Use a SELECT group rather than a series of IF-THEN statements when you have >a long series of mutually exclusive conditions. > >* SELECT of SAS9.2 >http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewe r >.htm#a000201966.htm >Use IF-THEN/ELSE statements for programs with few statements. > >I want to know the illustration(Reason) and then difference of the two >sentence. > >I want to know the description and example. > >Thank you!! > > > > > >[reference] > >http://support.sas.com/kb/10/197.html > >Problem Note 10197: Documentation incorrect about differences with SELECT >group and IF-THEN/ELSE statements > >The SAS Language Reference: Dictionary, Version 8 incorrectly states: > When you have a long series of mutually exclusive > conditions, using a SELECT group is more efficient than > using a series of IF-THEN statements because CPU time is > reduced. > >The CPU time is equivalent as long as the conditions are put in the >same order with each statement. > >The documentation is corrected beginning in SAS 9.1.


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