<?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 DECODE function in Proc SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/DECODE-function-in-Proc-SQL/m-p/516246#M139406</link>
    <description>&lt;P&gt;Hello everybody,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not sure how to convert the following Oracle SQL syntax with DECODE function in to Proc SQL syntax within SAS.&lt;/P&gt;&lt;P&gt;Your assistance would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DECODE(( con.AREA_CODE ),NULL,NULL,'('||( con.AREA_CODE )||') ')||( con.CONTACT_NUMBER )||DECODE(( con.EXTENSION ),NULL,NULL,' ext.'||( con.EXTENSION )) as Ind_Home_Phone ,&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Tue, 27 Nov 2018 09:00:21 GMT</pubDate>
    <dc:creator>RandomUserFS</dc:creator>
    <dc:date>2018-11-27T09:00:21Z</dc:date>
    <item>
      <title>DECODE function in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DECODE-function-in-Proc-SQL/m-p/516246#M139406</link>
      <description>&lt;P&gt;Hello everybody,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not sure how to convert the following Oracle SQL syntax with DECODE function in to Proc SQL syntax within SAS.&lt;/P&gt;&lt;P&gt;Your assistance would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DECODE(( con.AREA_CODE ),NULL,NULL,'('||( con.AREA_CODE )||') ')||( con.CONTACT_NUMBER )||DECODE(( con.EXTENSION ),NULL,NULL,' ext.'||( con.EXTENSION )) as Ind_Home_Phone ,&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2018 09:00:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DECODE-function-in-Proc-SQL/m-p/516246#M139406</guid>
      <dc:creator>RandomUserFS</dc:creator>
      <dc:date>2018-11-27T09:00:21Z</dc:date>
    </item>
    <item>
      <title>Re: DECODE function in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DECODE-function-in-Proc-SQL/m-p/516251#M139411</link>
      <description>&lt;P&gt;Decode is just another way of doing a case when statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So &amp;lt;variable is your variable, code is the short term you might have, and decode is the long term is the long value you want:&lt;/P&gt;
&lt;PRE&gt;decode(&amp;lt;variable&amp;gt;,&amp;lt;code&amp;gt;,&amp;lt;decode&amp;gt;,[&amp;lt;code&amp;gt;,&amp;lt;decode&amp;gt;])

case &amp;lt;variable&amp;gt; when &amp;lt;code&amp;gt; then &amp;lt;decode&amp;gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;when &amp;lt;code&amp;gt; then &amp;lt;decode&amp;gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else &amp;lt;value&amp;gt; end as &amp;lt;new_variable&amp;gt;

case when &amp;lt;condition&amp;gt; then &amp;lt;decode&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;when &amp;lt;condition&amp;gt; then &amp;lt;decode&amp;gt;
  &amp;nbsp; &amp;nbsp;else &amp;lt;value&amp;gt; end as &amp;lt;new_variable&amp;gt;

&lt;/PRE&gt;
&lt;P&gt;So if you had:&lt;/P&gt;
&lt;PRE&gt;xyz=decode(old_var,"a","something","b","else")&lt;/PRE&gt;
&lt;P&gt;The equivalent would be:&lt;/P&gt;
&lt;PRE&gt;case old_var when "a" then "something"
                      when "b" then "else"
                      else "" end as xyz&lt;/PRE&gt;
&lt;P&gt;I used the first method of case here, but either works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2018 09:13:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DECODE-function-in-Proc-SQL/m-p/516251#M139411</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-11-27T09:13:47Z</dc:date>
    </item>
  </channel>
</rss>

