<?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: Convert IF THEN statement to a CASE WHEN in an Advanced Expression in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Convert-IF-THEN-statement-to-a-CASE-WHEN-in-an-Advanced/m-p/344811#M22822</link>
    <description>&lt;P&gt;Yes I did. Thanks for the catch. Very grateful to all of you! The&amp;nbsp;SQL code worked! Have a wonderful rest of the day everyone!&lt;/P&gt;</description>
    <pubDate>Mon, 27 Mar 2017 21:36:56 GMT</pubDate>
    <dc:creator>cbonazzo</dc:creator>
    <dc:date>2017-03-27T21:36:56Z</dc:date>
    <item>
      <title>Convert IF THEN statement to a CASE WHEN in an Advanced Expression</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Convert-IF-THEN-statement-to-a-CASE-WHEN-in-an-Advanced/m-p/344758#M22814</link>
      <description>&lt;P&gt;Hell Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your time to help me with this road block I am having. I am working on someone else's code for recoding a combination of two variables and trying to create something similar in an advance expression. I keep getting an error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The original code was:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;*Create Think\_College column by recoding Think_about_College and Grade_when_Think_Coll as&lt;BR /&gt;Think_about_College:&lt;BR /&gt;ORIGINAL: 0=never&lt;BR /&gt;1=high&lt;BR /&gt;2=middle&lt;BR /&gt;3=elementary&lt;BR /&gt;4=as long as I can remember&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Grade_when_Think_Coll&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1=9&lt;BR /&gt;2=10&amp;nbsp;&lt;BR /&gt;3=11&amp;nbsp;&lt;BR /&gt;4=12&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NEW: 0=never&lt;BR /&gt;1=as long as I can remember&lt;BR /&gt;2=by grade 10 (includes elementary, middle, and high school grades 9 &amp;amp; 10)&lt;BR /&gt;3=after grade 10 (includes high school grades 10 and 11);&lt;/P&gt;&lt;P&gt;if Think_about_College=0&lt;BR /&gt;then Think_College=0;&lt;BR /&gt;if Think_about_College=4&lt;BR /&gt;then Think_College=1;&lt;BR /&gt;if Think_about_College=3 OR Think_about_College=2 OR Grade_when_Think_Coll=1 OR Grade_when_Think_Coll=2&lt;BR /&gt;then Think_College=2;&lt;BR /&gt;if Grade_when_Think_Coll=3 OR Grade_when_Think_Coll=4&lt;BR /&gt;then Think_College=3;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code I created in an advanced expression:&lt;/P&gt;&lt;P&gt;CASE WHEN t1.Think_About_Coll=0 then Think_College=0&lt;BR /&gt;CASE WHEN t1.Think_About_Coll=4 then Think_College=1&lt;BR /&gt;CASE WHEN t1.Think_About_Coll=3 OR t1.Think_About_Coll=2 OR&amp;nbsp;t1.Grade_Think_About_Coll=1 OR t1.Grade_Think_About_Coll=2 then Think_College=2&lt;BR /&gt;CASE WHEN t1.Grade_Think_About_Coll=3 OR t1.Grade_Think_About_Coll=4&lt;BR /&gt;then Think_College=3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know it is probably something simple but I need your help. Thank you for your time!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Claude&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2017 19:57:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Convert-IF-THEN-statement-to-a-CASE-WHEN-in-an-Advanced/m-p/344758#M22814</guid>
      <dc:creator>cbonazzo</dc:creator>
      <dc:date>2017-03-27T19:57:17Z</dc:date>
    </item>
    <item>
      <title>Re: Convert IF THEN statement to a CASE WHEN in an Advanced Expression</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Convert-IF-THEN-statement-to-a-CASE-WHEN-in-an-Advanced/m-p/344766#M22815</link>
      <description>&lt;P&gt;That's a bit garbled in how it looks and what you're trying to do.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm going to use this as your starting point:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if Think_about_College=0
then Think_College=0;
if Think_about_College=4
then Think_College=1;
if Think_about_College=3 OR Think_about_College=2 OR Grade_when_Think_Coll=1 OR Grade_when_Think_Coll=2
then Think_College=2;
if Grade_when_Think_Coll=3 OR Grade_when_Think_Coll=4
then Think_College=3;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The SQL equivalent would be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case when think_about_college =1 then 0
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; when think_about_college = 4 then 1
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; when think_about_college in (3, 2) or Grade_when_Think_Coll=1 OR Grade_when_Think_Coll=2 then 2
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; when&amp;nbsp;Grade_when_Think_Coll in (3, 4) then 3
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else -9
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end as think_college&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: change otherwise to else&lt;/P&gt;
&lt;P&gt;SAS note regarding this with details and instructions:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/kb/32/160.html" target="_blank"&gt;http://support.sas.com/kb/32/160.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Documentation with examples:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/documentation/cdl/en/sqlproc/69822/HTML/default/viewer.htm#n0a85s0ijz65irn1h3jtariooea5.htm" target="_blank"&gt;https://support.sas.com/documentation/cdl/en/sqlproc/69822/HTML/default/viewer.htm#n0a85s0ijz65irn1h3jtariooea5.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2017 20:15:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Convert-IF-THEN-statement-to-a-CASE-WHEN-in-an-Advanced/m-p/344766#M22815</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-27T20:15:44Z</dc:date>
    </item>
    <item>
      <title>Re: Convert IF THEN statement to a CASE WHEN in an Advanced Expression</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Convert-IF-THEN-statement-to-a-CASE-WHEN-in-an-Advanced/m-p/344768#M22816</link>
      <description>&lt;P&gt;Possibly:&lt;/P&gt;
&lt;PRE&gt;CASE 
   WHEN t1.Think_About_Coll=0 then 0
   WHEN t1.Think_About_Coll=4 then 1
   WHEN t1.Think_About_Coll in (3, 2) OR t1.Grade_Think_About_Coll in (1, 2) then 2
   WHEN t1.Grade_Think_About_Coll in(3, 4) then =3 
   else . &lt;BR /&gt;end as Think_College&lt;/PRE&gt;
&lt;P&gt;Case starts the statement,&amp;nbsp; END AS resultvariable ends it. Each sub-clause is When conditon then Value (value could be a variable, a calculation or even subquery that yields a single value)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2017 20:12:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Convert-IF-THEN-statement-to-a-CASE-WHEN-in-an-Advanced/m-p/344768#M22816</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-27T20:12:40Z</dc:date>
    </item>
    <item>
      <title>Re: Convert IF THEN statement to a CASE WHEN in an Advanced Expression</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Convert-IF-THEN-statement-to-a-CASE-WHEN-in-an-Advanced/m-p/344769#M22817</link>
      <description>&lt;P&gt;Easy, common mistake. SQL is a pain!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In a SQL select, the result variable name comes at the end, after an AS clause.&lt;/P&gt;
&lt;P&gt;In the IF/THEN clauses, you just put the conditions and the desired result.&lt;/P&gt;
&lt;P&gt;so:&lt;/P&gt;
&lt;P&gt;CASE WHEN t1.Think_About_Coll=0 then 0&lt;BR /&gt;CASE WHEN t1.Think_About_Coll=4 then 1&lt;BR /&gt;etc.&lt;/P&gt;
&lt;P&gt;and EG will fill in the AS Think_College when you supply the variable name.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2017 20:12:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Convert-IF-THEN-statement-to-a-CASE-WHEN-in-an-Advanced/m-p/344769#M22817</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2017-03-27T20:12:37Z</dc:date>
    </item>
    <item>
      <title>Re: Convert IF THEN statement to a CASE WHEN in an Advanced Expression</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Convert-IF-THEN-statement-to-a-CASE-WHEN-in-an-Advanced/m-p/344805#M22820</link>
      <description>&lt;P&gt;I think I am getting close!! I forgot to mention it is a character variable. I made the change. But got another error message:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 ;*';*";*/;quit;run;&lt;BR /&gt;2 OPTIONS PAGENO=MIN;&lt;BR /&gt;3 OPTION DEBUG=DBMS_SELECT SQL_IP_TRACE=(NOTE, SOURCE);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;4 PROC SQL NOEXEC;&lt;BR /&gt;5 SELECT (CASE&lt;BR /&gt;6 WHEN t1.Think_About_Coll='0' then '0'&lt;BR /&gt;7 WHEN t1.Think_About_Coll='4' then '1'&lt;BR /&gt;8 WHEN t1.Think_About_Coll in ( '3' , '2' ) OR t1.Grade_Think_About_Coll in ( '1' , '2' ) then '2'&lt;BR /&gt;9 WHEN t1.Grade_Think_About_Coll in( '3' , '4' ) then = '3'&lt;BR /&gt;_&lt;BR /&gt;22&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant,&lt;BR /&gt;a missing value, BTRIM, INPUT, PUT, SUBSTRING, USER.&lt;/P&gt;&lt;P&gt;10 else '.'&lt;BR /&gt;11 end as Think_College) AS CALCULATION&lt;BR /&gt;__&lt;BR /&gt;22&lt;BR /&gt;76&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, ), *, **, +, -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, ?, AND, BETWEEN,&lt;BR /&gt;CONTAINS, EQ, EQT, GE, GET, GT, GTT, IN, IS, LE, LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, ^, ^=, |, ||, ~, ~=.&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;&lt;P&gt;12 FROM WORK.SELECTION_RENAMING_RECODING t1;&lt;BR /&gt;13 QUIT;&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;BR /&gt;&lt;BR /&gt;14 %PUT SQL_IPTRACE_RESULT=&amp;amp;SYS_SQL_IP_ALL;&lt;BR /&gt;SQL_IPTRACE_RESULT=-1&lt;BR /&gt;15 OPTIONS SQL_IP_TRACE=(NONE);&lt;BR /&gt;16 QUIT; RUN;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2017 21:15:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Convert-IF-THEN-statement-to-a-CASE-WHEN-in-an-Advanced/m-p/344805#M22820</guid>
      <dc:creator>cbonazzo</dc:creator>
      <dc:date>2017-03-27T21:15:39Z</dc:date>
    </item>
    <item>
      <title>Re: Convert IF THEN statement to a CASE WHEN in an Advanced Expression</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Convert-IF-THEN-statement-to-a-CASE-WHEN-in-an-Advanced/m-p/344808#M22821</link>
      <description>&lt;P&gt;You forgot to remove an = sign on one of the WHEN (3) statement.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2017 21:22:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Convert-IF-THEN-statement-to-a-CASE-WHEN-in-an-Advanced/m-p/344808#M22821</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-27T21:22:28Z</dc:date>
    </item>
    <item>
      <title>Re: Convert IF THEN statement to a CASE WHEN in an Advanced Expression</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Convert-IF-THEN-statement-to-a-CASE-WHEN-in-an-Advanced/m-p/344811#M22822</link>
      <description>&lt;P&gt;Yes I did. Thanks for the catch. Very grateful to all of you! The&amp;nbsp;SQL code worked! Have a wonderful rest of the day everyone!&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2017 21:36:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Convert-IF-THEN-statement-to-a-CASE-WHEN-in-an-Advanced/m-p/344811#M22822</guid>
      <dc:creator>cbonazzo</dc:creator>
      <dc:date>2017-03-27T21:36:56Z</dc:date>
    </item>
  </channel>
</rss>

