<?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 Re: Case Statement Multiple Ends or One? in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Case-Statement-Multiple-Ends-or-One/m-p/408886#M26225</link>
    <description>&lt;P&gt;So it doesn't slow it down if there is only one END vs multiple ends?&amp;nbsp; My main concern was slowing down the process but if it doesn't seem to make a difference then that's great news&lt;/P&gt;</description>
    <pubDate>Mon, 30 Oct 2017 19:48:44 GMT</pubDate>
    <dc:creator>mmagnuson</dc:creator>
    <dc:date>2017-10-30T19:48:44Z</dc:date>
    <item>
      <title>Case Statement Multiple Ends or One?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Case-Statement-Multiple-Ends-or-One/m-p/407429#M26149</link>
      <description>&lt;P&gt;I have started to get the hang of CASE statements and found that I write them differently than other people.&lt;/P&gt;&lt;P&gt;Usually I do something similar to this,&lt;/P&gt;&lt;P&gt;Case when Name=Joe 'Yes' else 'NO'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;when Name=Jane 'Yes' else 'No'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Other CASE statements I've seen use CASE ELSE and then multiple ENDs:&lt;/P&gt;&lt;P&gt;Case when Name=Joe 'Yes' else&lt;/P&gt;&lt;P&gt;Case when&amp;nbsp;Name=Jane 'Yes' else 'No'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end end&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is one way more efficient?&amp;nbsp; I find that using only one END makes it feel neat but I don't want to end up slowing the program down by accident.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2017 18:57:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Case-Statement-Multiple-Ends-or-One/m-p/407429#M26149</guid>
      <dc:creator>mmagnuson</dc:creator>
      <dc:date>2017-10-25T18:57:13Z</dc:date>
    </item>
    <item>
      <title>Re: Case Statement Multiple Ends or One?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Case-Statement-Multiple-Ends-or-One/m-p/407432#M26150</link>
      <description>&lt;P&gt;In general the advice for speeding up processing time for CASE statement (or DO SELECT statement or any other way of coding a series of tests) is to make sure that the most common cases are listed first, since once it finds a match it stops having to perform the other tests.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You code is messed, but nesting the CASE statements should not slow your program down.&amp;nbsp; It really should be doing the same number of comparisons.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
select
  name
, case when (name='Alfred') then 'Yes' 
       when (name='Jane') then 'Yes' 
       else 'No'
  end as FLAG
from sashelp.class
;

select
  name
, case when (name='Alfred') then 'Yes' 
       else case when (name='Jane') then 'Yes' 
                 else 'No'
            end
  end as FLAG
from sashelp.class
;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you could just go ahead and run some timing tests using your real data or example data and see if there is any impact.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2017 21:31:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Case-Statement-Multiple-Ends-or-One/m-p/407432#M26150</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-10-25T21:31:34Z</dc:date>
    </item>
    <item>
      <title>Re: Case Statement Multiple Ends or One?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Case-Statement-Multiple-Ends-or-One/m-p/407469#M26151</link>
      <description>&lt;P&gt;From my memory, neither of your options looked right. I reviewed the PROC SQL documentation. Here's an extract from it, that describes two ways to use the CASE statement. I suggest you stick to them, simply so that other programmers won't get confused.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I had run across either of the options that you've shown, I'd have to run some tests to satisfy myself that they worked correctly. Even then, I'd probably recode them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tom&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CASE Expression&lt;/P&gt;
&lt;DIV class="xis-refDictEntry"&gt;
&lt;DIV class="xis-exampleBlock"&gt;
&lt;H2 class="xis-title"&gt;Example&lt;/H2&gt;
&lt;DIV class="xis-example"&gt;&lt;A id="n199ceur9xxrqdn0zcl5q301zbhq" target="_blank"&gt;&lt;/A&gt;
&lt;DIV class="xis-paragraph"&gt;&lt;A id="n1sl4ars54erl6n1ujbsv309451i" target="_blank"&gt;&lt;/A&gt;The following two PROC SQL steps show two equivalent CASE expressions that create a character column with the strings in the THEN clause. The CASE expression in the second PROC SQL step is a shorthand method that is useful when all the comparisons are with the same column.
&lt;PRE class="xis-codeFragment"&gt;proc sql;
   select Name, case
                when Continent = 'North America' then 'Continental U.S.'
                when Continent = 'Oceania' then 'Pacific Islands'
                else 'None'
                end as Region
      from states;

proc sql;
   select Name, case Continent
                when 'North America' then 'Continental U.S.'
                when 'Oceania' then 'Pacific Islands'
                else 'None'
                end as Region
      from states;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;DIV class="xis-note"&gt;&lt;A id="p0as96fhyfmvajn1ry6n6is5xkjc" target="_blank"&gt;&lt;/A&gt;&lt;SPAN class="xis-noteGenText"&gt;Note: &lt;/SPAN&gt;When you use the shorthand method, the conditions must all be equality tests. That is, they cannot use comparison operators or other types of operators.&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 25 Oct 2017 20:49:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Case-Statement-Multiple-Ends-or-One/m-p/407469#M26151</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2017-10-25T20:49:45Z</dc:date>
    </item>
    <item>
      <title>Re: Case Statement Multiple Ends or One?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Case-Statement-Multiple-Ends-or-One/m-p/408700#M26208</link>
      <description>&lt;P&gt;I used this case statement to create a computed column.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2017 14:39:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Case-Statement-Multiple-Ends-or-One/m-p/408700#M26208</guid>
      <dc:creator>mmagnuson</dc:creator>
      <dc:date>2017-10-30T14:39:53Z</dc:date>
    </item>
    <item>
      <title>Re: Case Statement Multiple Ends or One?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Case-Statement-Multiple-Ends-or-One/m-p/408722#M26212</link>
      <description>&lt;P&gt;When I use the advanced expression builder, I get the following scaffold code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;CASE  
   WHEN &amp;lt;condition&amp;gt;
   THEN &amp;lt;value&amp;gt;
   ELSE &amp;lt;value&amp;gt;
END&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With this code, just copy the "when...then" lines as many times as you need, and leave one "else" after them, followed by "end". That should give you nice, clean code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tom&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2017 15:04:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Case-Statement-Multiple-Ends-or-One/m-p/408722#M26212</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2017-10-30T15:04:19Z</dc:date>
    </item>
    <item>
      <title>Re: Case Statement Multiple Ends or One?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Case-Statement-Multiple-Ends-or-One/m-p/408724#M26213</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/142148"&gt;@mmagnuson&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I used this case statement to create a computed column.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So after the END you put the name you want the computed column to have.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2017 15:06:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Case-Statement-Multiple-Ends-or-One/m-p/408724#M26213</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-10-30T15:06:18Z</dc:date>
    </item>
    <item>
      <title>Re: Case Statement Multiple Ends or One?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Case-Statement-Multiple-Ends-or-One/m-p/408886#M26225</link>
      <description>&lt;P&gt;So it doesn't slow it down if there is only one END vs multiple ends?&amp;nbsp; My main concern was slowing down the process but if it doesn't seem to make a difference then that's great news&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2017 19:48:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Case-Statement-Multiple-Ends-or-One/m-p/408886#M26225</guid>
      <dc:creator>mmagnuson</dc:creator>
      <dc:date>2017-10-30T19:48:44Z</dc:date>
    </item>
  </channel>
</rss>

