<?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 CASE WHEN Statement in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/CASE-WHEN-Statement/m-p/30148#M4094</link>
    <description>I'm trying to get the following case,when,then,else expression to work in a query:&lt;BR /&gt;
&lt;BR /&gt;
CASE WHEN FIELD1 IS 0 THEN 'N/A' ELSE FIELD1 END&lt;BR /&gt;
&lt;BR /&gt;
Here is the error I am getting in my log:&lt;BR /&gt;
ERROR: Result of WHEN clause 2 is not the same data type as the preceding results.&lt;BR /&gt;
&lt;BR /&gt;
Is there any way to return a character from a numeric field in a case when statement?</description>
    <pubDate>Wed, 09 Jul 2008 13:53:34 GMT</pubDate>
    <dc:creator>mdavidson</dc:creator>
    <dc:date>2008-07-09T13:53:34Z</dc:date>
    <item>
      <title>CASE WHEN Statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/CASE-WHEN-Statement/m-p/30148#M4094</link>
      <description>I'm trying to get the following case,when,then,else expression to work in a query:&lt;BR /&gt;
&lt;BR /&gt;
CASE WHEN FIELD1 IS 0 THEN 'N/A' ELSE FIELD1 END&lt;BR /&gt;
&lt;BR /&gt;
Here is the error I am getting in my log:&lt;BR /&gt;
ERROR: Result of WHEN clause 2 is not the same data type as the preceding results.&lt;BR /&gt;
&lt;BR /&gt;
Is there any way to return a character from a numeric field in a case when statement?</description>
      <pubDate>Wed, 09 Jul 2008 13:53:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/CASE-WHEN-Statement/m-p/30148#M4094</guid>
      <dc:creator>mdavidson</dc:creator>
      <dc:date>2008-07-09T13:53:34Z</dc:date>
    </item>
    <item>
      <title>Re: CASE WHEN Statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/CASE-WHEN-Statement/m-p/30149#M4095</link>
      <description>&lt;P&gt;Hi: &lt;BR /&gt; If you're using SQL code, then your CASE statement needs an "&lt;STRONG&gt;AS&lt;/STRONG&gt;" to create the "new" column. In the example below, NEWVAR is a character variable that is created based on the CASE condition that an observation meets.&lt;BR /&gt; &lt;BR /&gt; cynthia&lt;BR /&gt; &lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql;
create table work.newclass as
select a.Name,
a.Sex,
a.Age,
(case
when a.sex = 'F' and a.age lt 13 then 'One'
when a.sex = 'F' and a.age ge 13 then 'Two'
when a.sex = 'M' and a.age lt 14 then 'Three'
when a.sex = 'M' and a.age ge 14 then 'Four'
else 'None' 
end) as newvar
from sashelp.class as a;
quit;

proc print data=newclass;
title 'SQL CASE Example ';
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Jul 2017 16:48:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/CASE-WHEN-Statement/m-p/30149#M4095</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2017-07-27T16:48:00Z</dc:date>
    </item>
    <item>
      <title>Re: CASE WHEN Statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/CASE-WHEN-Statement/m-p/30150#M4096</link>
      <description>Cynthia,&lt;BR /&gt;
&lt;BR /&gt;
I'm using the GUI approach, I will try and mess with the SAS code to get this to work...</description>
      <pubDate>Wed, 09 Jul 2008 16:51:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/CASE-WHEN-Statement/m-p/30150#M4096</guid>
      <dc:creator>mdavidson</dc:creator>
      <dc:date>2008-07-09T16:51:45Z</dc:date>
    </item>
    <item>
      <title>Re: CASE WHEN Statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/CASE-WHEN-Statement/m-p/30151#M4097</link>
      <description>Hi:&lt;BR /&gt;
  In the GUI window, there's a place to click for a COMPUTED column when you build the query -- it's over to the left of the Query window -- that's what you want. Then in the Expression editor, you add the WHOLE CASE expression &lt;BR /&gt;
(CASE ... END) in the Expression editor. &lt;BR /&gt;
&lt;BR /&gt;
  Do NOT add the AS portion of the clause in the Expression Editor -- only the whole clause in parentheses. EG adds the AS from the information you put into the Computed column window for the name of the variable. Otherwise EG uses a funny name like Calculated1 or Calculation1 as the name of the new variable.&lt;BR /&gt;
&lt;BR /&gt;
  It's probably worth working with the GUI window a bit to see if you can figure it out. It sticks in my mind that there were some differences in the syntax of the CASE clause in earlier versions of EG versus EG 4.1 -- but basically I believe that in either version you add the entire CASE clause into the Expression Editor.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Wed, 09 Jul 2008 17:14:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/CASE-WHEN-Statement/m-p/30151#M4097</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-07-09T17:14:17Z</dc:date>
    </item>
  </channel>
</rss>

