BookmarkSubscribeRSS Feed
kk760105
Calcite | Level 5
* WEB PAGE :
http://web.utk.edu/sas/OnlineTutor/1.2/en/60477/m83/m83_11.htm

"Using DO Groups Efficiently"

"Remember to use the following criteria when choosing which technique is
more efficient"

---------------------------------------------------------------------------
| IF-THEN/ELSE Statements | SELECT/WHEN Statements |
---------------------------------------------------------------------------
The number of conditions| few | many |

The distribution of a | not uniform | uniform |
variable's values

The type of variable | character | numeric |
----------------------------------------------------------------------------



I want to know the efficient difference of the IF-THEN/ELSE Statements and
SELECT/WHEN Statements

I tried to understand the efficient,but can't understand through SAS help.

I want to know the description and example for the difference.
8 REPLIES 8
Patrick
Opal | Level 21
Hi

I believe from a performance point of view the difference between "if then else" and "select when" is rather neglectable.

The most important thing for both ways will be to order the cases descending according to probability (meaning: have the case which will be most often true first so all the other comparisons will be skipped).

Also from a performance perspective: Things like reducing data volumes as early as possible, minimizing passes through data / full table scans, avoiding unnecessary sorting and minimizing disk I/O operations are much more relevant.

HTH
Patrick
kk760105
Calcite | Level 5
Particularly, I want to know the efficient difference for the "The type of variable"
(Character and Numeric)
Cynthia_sas
SAS Super FREQ
Hi,
IF/THEN/ELSE and/or SELECT/WHEN are frequently used for TABLE lookups. So instead of focussing on only those techniques (which are really about the same in terms of processing), perhaps you should broaden your investigation into a discussion of table lookup efficiencies and overall efficiencies:
http://www2.sas.com/proceedings/forum2008/095-2008.pdf
http://www2.sas.com/proceedings/forum2007/042-2007.pdf
http://support.sas.com/resources/papers/sgf09/336-2009.pdf

cynthia
art297
Opal | Level 21
Cynthia,

The same thread has been active on SAS-L the last couple of days. Nat Wooding, as part of that thread, did an interesting comparison regarding the numeric vs character difference ( see: http://www.listserv.uga.edu/cgi-bin/wa?A2=ind1106c&L=sas-l&D=1&O=D&P=14099).

Basically, if his tests were flawed, he showed that the difference does appear to be quite dramatic regarding character variables. In those cases, it appears that the if-then scenario fares much better.

Art
---------
> Hi,
> IF/THEN/ELSE and/or SELECT/WHEN are frequently
> used for TABLE lookups. So instead of focussing on
> only those techniques (which are really about the
> same in terms of processing), perhaps you should
> broaden your investigation into a discussion of
> table lookup efficiencies and overall efficiencies:
> ttp://www2.sas.com/proceedings/forum2008/095-2008.pdf
> http://www2.sas.com/proceedings/forum2007/042-2007.pdf
>
> http://support.sas.com/resources/papers/sgf09/336-2009
> .pdf
>
> ynthia
Cynthia_sas
SAS Super FREQ
Hi:
Interesting results -- as with anything to do with efficiency -- it depends on your operating system, your data and your constraints, including programmer time for maintenance, etc. And whether you are optimizing for I/O, for CPU processing time, for clock time, for programmer maintenance time, or any number of factors. I always recommend that people run benchmarks with their data on their OS.

Nat provides a good example of pumping data through a program to generate benchmarking results. The next step would be to run a typical program using test data or a subset of the real data -- one with SELECT/WHEN and one with IF/THEN/ELSE or other TABLE lookup techniques (such as PROC FORMAT or hash table) to compare the performance of the real data to that of the benchmark with fake data.

cynthia
Ksharp
Super User
I remembered that Arther.Carpenter has written a papa about this question before. He prefer to use select/when which is more efficient then if/else, Especially when you use expression in () of when not in select .Such as : select(); when(sex='F') .... when(sex='M')....
Certainly, Hope Art.C can write some words to explain this situation more.
Art.C is here now? 🙂


Ksharp
ArtC
Rhodochrosite | Level 12
Thank you for the confidence Ksharp, but I suspect those may have been someone else's recommendations. Bob Virgle did a fair number of tests on these statements in his efficiencies book a number of years ago. And while I did write about the relative efficiencies in the narrow context of performing table look ups. I would defer to Cynthia's comment that you need to know your data, your machine, your situation. That said I find the differences between the comparisons on numerics and characters to be very interesting and probably worthy of more research.
kk760105
Calcite | Level 5
Thank you, your kind words !!


But, I don't know the fundamental reason.

1. Why are the diffrent for the Character and Numeric variable between IF/ELSE
and Select statement?


2. Why are the diffrent for The distribution of variable's values between IF/ELSE
and Select statement?

3. Why are the diffrent for the number of conditions between IF/ELSE
and Select statement? Message was edited by: kk760105

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 1119 views
  • 0 likes
  • 6 in conversation