<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic More efficient -(Select  group and IF )why ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/More-efficient-Select-group-and-IF-why/m-p/70593#M15274</link>
    <description>Hi , &lt;BR /&gt;
I'm preparing for SAs certification Base exam . I have one question . Which will be more efficient between Select group and If statment. I coded this programs for practice  using IF statment in one datasep and select group in another . both does same tasks  but i would like to know which will be more efficeint for usage and why ?  I know here I'm using test data so efficiney cant be known  but still I'm curious to know which one will be better to use between select group and IF/then else statment and why ?&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Program 1&lt;BR /&gt;
DATA PATIENT;                    &lt;BR /&gt;
  INPUT ID $  SALARY DEPT $;     &lt;BR /&gt;
DATALINES;                       &lt;BR /&gt;
1129 10000 A                     &lt;BR /&gt;
1387 10000 B                     &lt;BR /&gt;
2304 10000 C&lt;BR /&gt;
4759 20000 E&lt;BR /&gt;
5438 20000 F&lt;BR /&gt;
6488 20000 G&lt;BR /&gt;
9012 20000 H&lt;BR /&gt;
;              &lt;BR /&gt;
DATA PATIENT1;                                                  &lt;BR /&gt;
     SET PATIENT;                                               &lt;BR /&gt;
    LENGTH DEPT1 $6.; &lt;BR /&gt;
IF DEPT IN ('A','B','C','D'') THEN DO DEPT1='ABCD'; &lt;BR /&gt;
ELSE IF DEPT IN  ('F','G','H','I'')  &lt;BR /&gt;
THEN DEPT1='FGHI';   &lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
DATA PATIENT2;                                    &lt;BR /&gt;
     SET PATIENT;                                 &lt;BR /&gt;
    LENGTH DEPT2 $6.;                           &lt;BR /&gt;
                                                  &lt;BR /&gt;
    SELECT (DEPT);                                &lt;BR /&gt;
       WHEN ('A','B','C','D') DEPT2='ABCDE';      &lt;BR /&gt;
       WHEN ('F','G','H','I') DEPT2='FGHI';    &lt;BR /&gt;
       OTHERWISE;                                 &lt;BR /&gt;
    END;      &lt;BR /&gt;
Run;&lt;BR /&gt;
Thanx &lt;BR /&gt;
Manish</description>
    <pubDate>Fri, 11 Sep 2009 07:07:51 GMT</pubDate>
    <dc:creator>er_awasthi</dc:creator>
    <dc:date>2009-09-11T07:07:51Z</dc:date>
    <item>
      <title>More efficient -(Select  group and IF )why ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/More-efficient-Select-group-and-IF-why/m-p/70593#M15274</link>
      <description>Hi , &lt;BR /&gt;
I'm preparing for SAs certification Base exam . I have one question . Which will be more efficient between Select group and If statment. I coded this programs for practice  using IF statment in one datasep and select group in another . both does same tasks  but i would like to know which will be more efficeint for usage and why ?  I know here I'm using test data so efficiney cant be known  but still I'm curious to know which one will be better to use between select group and IF/then else statment and why ?&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Program 1&lt;BR /&gt;
DATA PATIENT;                    &lt;BR /&gt;
  INPUT ID $  SALARY DEPT $;     &lt;BR /&gt;
DATALINES;                       &lt;BR /&gt;
1129 10000 A                     &lt;BR /&gt;
1387 10000 B                     &lt;BR /&gt;
2304 10000 C&lt;BR /&gt;
4759 20000 E&lt;BR /&gt;
5438 20000 F&lt;BR /&gt;
6488 20000 G&lt;BR /&gt;
9012 20000 H&lt;BR /&gt;
;              &lt;BR /&gt;
DATA PATIENT1;                                                  &lt;BR /&gt;
     SET PATIENT;                                               &lt;BR /&gt;
    LENGTH DEPT1 $6.; &lt;BR /&gt;
IF DEPT IN ('A','B','C','D'') THEN DO DEPT1='ABCD'; &lt;BR /&gt;
ELSE IF DEPT IN  ('F','G','H','I'')  &lt;BR /&gt;
THEN DEPT1='FGHI';   &lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
DATA PATIENT2;                                    &lt;BR /&gt;
     SET PATIENT;                                 &lt;BR /&gt;
    LENGTH DEPT2 $6.;                           &lt;BR /&gt;
                                                  &lt;BR /&gt;
    SELECT (DEPT);                                &lt;BR /&gt;
       WHEN ('A','B','C','D') DEPT2='ABCDE';      &lt;BR /&gt;
       WHEN ('F','G','H','I') DEPT2='FGHI';    &lt;BR /&gt;
       OTHERWISE;                                 &lt;BR /&gt;
    END;      &lt;BR /&gt;
Run;&lt;BR /&gt;
Thanx &lt;BR /&gt;
Manish</description>
      <pubDate>Fri, 11 Sep 2009 07:07:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/More-efficient-Select-group-and-IF-why/m-p/70593#M15274</guid>
      <dc:creator>er_awasthi</dc:creator>
      <dc:date>2009-09-11T07:07:51Z</dc:date>
    </item>
    <item>
      <title>Re: More efficient -(Select  group and IF )why ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/More-efficient-Select-group-and-IF-why/m-p/70594#M15275</link>
      <description>Hi i tried executing multiple statments using Do loops in select statament and i got the desired reuslts.&lt;BR /&gt;
&lt;BR /&gt;
SELECT (DEPT);                                                &lt;BR /&gt;
   WHEN ('A','B','C','D') DO; DEPT1='ABCDE'; DEPT2='LGH'; END;&lt;BR /&gt;
   WHEN ('F','G','H','I') DEPT1='FGHIJKL';                    &lt;BR /&gt;
   OTHERWISE;                                                 &lt;BR /&gt;
END;     &lt;BR /&gt;
&lt;BR /&gt;
I believe the performance of If statments and  select statments and if statments depends on the data. If Program encounters True data  on the top itself  ( top of If and select statment ) Performance will be good but Which one to choose Between them while coding and Why ? &lt;BR /&gt;
&lt;BR /&gt;
Thanx &lt;BR /&gt;
Manish</description>
      <pubDate>Fri, 11 Sep 2009 09:03:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/More-efficient-Select-group-and-IF-why/m-p/70594#M15275</guid>
      <dc:creator>er_awasthi</dc:creator>
      <dc:date>2009-09-11T09:03:38Z</dc:date>
    </item>
    <item>
      <title>Re: More efficient -(Select  group and IF )why ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/More-efficient-Select-group-and-IF-why/m-p/70595#M15276</link>
      <description>I would say that IF/SELECT are quit equal when it comes to compare performance.&lt;BR /&gt;
There are many other things that has higher impact on performance.&lt;BR /&gt;
But if you want to gain the best performance, I believe in IF you should put the most common true condition first. I'm not sure if this applies to SELECT as well.&lt;BR /&gt;
Generally, I'll favor SELECT if there are more than two possible outcomes, since it is more readable.&lt;BR /&gt;
&lt;BR /&gt;
/Linus</description>
      <pubDate>Fri, 11 Sep 2009 10:03:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/More-efficient-Select-group-and-IF-why/m-p/70595#M15276</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2009-09-11T10:03:32Z</dc:date>
    </item>
    <item>
      <title>Re: More efficient -(Select  group and IF )why ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/More-efficient-Select-group-and-IF-why/m-p/70596#M15277</link>
      <description>Thanx..&lt;BR /&gt;
I got it the performance depends on By putting most common condition first and this applies to both If/select statment . This works for Select statment also Thanx for clearing my doubt&lt;BR /&gt;
&lt;BR /&gt;
Manish</description>
      <pubDate>Sat, 12 Sep 2009 03:58:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/More-efficient-Select-group-and-IF-why/m-p/70596#M15277</guid>
      <dc:creator>er_awasthi</dc:creator>
      <dc:date>2009-09-12T03:58:41Z</dc:date>
    </item>
  </channel>
</rss>

