|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|
|Content-Type: ||text/plain; charset=ISO-8859-1|
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:
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.
On Wed, 13 Apr 2011 05:11:28 -0400, Seung-min Baek <760105@HANMAIL.NET>
>Now, I have the question.
>* IF-THEN / ELSE of SAS9.2 :
>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
>Use IF-THEN/ELSE statements for programs with few statements.
>I want to know the illustration(Reason) and then difference of the two
>I want to know the description and example.
>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
>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.