<?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: Problem with IF Statement in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-IF-Statement/m-p/66295#M6661</link>
    <description>Hi:&lt;BR /&gt;
  It is generally useful if you post your WHOLE program...not just the bits where you have issues...and provide a bit of context. For example, if you tried to put an IF statement into the SQL query built by EG, I would not expect this to work at all. If you tried to put an IF statement into PROC SQL code in a code node, then I would not expect -that- to work either.&lt;BR /&gt;
&lt;BR /&gt;
  If you are writing a DATA step program and want to put an IF statement into a DATA step program, then you need to understand how SAS internally stores missing values and how the internal storage of missing values is different between SAS datasets and, an RDBMS (such as Oracle or DB2). This Tech Support note provides some background:&lt;BR /&gt;
&lt;A href="http://support.sas.com/kb/23/226.html" target="_blank"&gt;http://support.sas.com/kb/23/226.html&lt;/A&gt; and&lt;BR /&gt;
&lt;A href="http://support.sas.com/resources/papers/resultsets.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/resultsets.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
  For the documentation on working with SAS variables, this site has the basic concepts on missing values:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#/documentation/cdl/en/lrcon/62955/HTML/default/a001292604.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#/documentation/cdl/en/lrcon/62955/HTML/default/a001292604.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
  Without understanding more about how you're using your IF statement (PROC SQL or DATA step program), the only help that can be offered are suggestions to read the documentation and look for examples.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
    <pubDate>Mon, 23 Aug 2010 16:49:42 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2010-08-23T16:49:42Z</dc:date>
    <item>
      <title>Problem with IF Statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-IF-Statement/m-p/66290#M6656</link>
      <description>Hi All,&lt;BR /&gt;
&lt;BR /&gt;
I have built a simple IF statement but seem to be getting errors;&lt;BR /&gt;
&lt;BR /&gt;
  (IF t3.6MthAvgPayTerms IsNull then 'N/A';&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, LE, LET, LIKE, LT, LTT, NE, NET, OR, ^=, |, ||, ~=.  &lt;BR /&gt;
&lt;BR /&gt;
ERROR 76-322: Syntax error, statement will be ignored.&lt;BR /&gt;
&lt;BR /&gt;
36                                                               IF t2.Account_Status ='Live' AND t3.'6MthAvgPayTerms'n&amp;lt;60 then&lt;BR /&gt;
                                                                 __&lt;BR /&gt;
                                                                 180&lt;BR /&gt;
ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;BR /&gt;
&lt;BR /&gt;
37                     'Good';&lt;BR /&gt;
37       !                     IF t2.Account_Status='Live' AND t3.'6MthAvgPayTerms'n &amp;gt;=60 AND t3.'6MthAvgPayTerms'n &amp;lt;90 then&lt;BR /&gt;
                               __&lt;BR /&gt;
                               180&lt;BR /&gt;
ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;BR /&gt;
&lt;BR /&gt;
2                                                          The SAS System                              09:18 Monday, August 23, 2010&lt;BR /&gt;
&lt;BR /&gt;
38                     'Indeterminate';&lt;BR /&gt;
38       !                              IF t3.'6MthAvgPayTerms'n &amp;gt;=90 then 'Bad';&lt;BR /&gt;
                                        __&lt;BR /&gt;
                                        180&lt;BR /&gt;
ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;BR /&gt;
&lt;BR /&gt;
38                                                                               ) AS 'Good Bad 'n&lt;BR /&gt;
                                                                                 _&lt;BR /&gt;
                                                                                 180&lt;BR /&gt;
ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Can someone help?&lt;BR /&gt;
&lt;BR /&gt;
Statement: &lt;BR /&gt;
&lt;BR /&gt;
IF t3.6MthAvgPayTerms IsNull then 'N/A'; IF t2.Account_Status ='Live' AND t3.'6MthAvgPayTerms'n&amp;lt;60 then 'Good'; IF t2.Account_Status='Live' AND t3.'6MthAvgPayTerms'n &amp;gt;=60 AND t3.'6MthAvgPayTerms'n &amp;lt;90 then 'Indeterminate'; IF t3.'6MthAvgPayTerms'n &amp;gt;=90 then 'Bad';&lt;BR /&gt;
&lt;BR /&gt;
Thanks,</description>
      <pubDate>Mon, 23 Aug 2010 10:23:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-IF-Statement/m-p/66290#M6656</guid>
      <dc:creator>thegraduate</dc:creator>
      <dc:date>2010-08-23T10:23:33Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with IF Statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-IF-Statement/m-p/66291#M6657</link>
      <description>assuming your use of "is Null" indicates this syntax problem arises in sql, in which context IF is not valid, use the SQL equivalent&lt;BR /&gt;
   case when something then result1           &lt;BR /&gt;
when something_more then result2          &lt;BR /&gt;
else final_result &lt;BR /&gt;
end&lt;BR /&gt;
as new_column</description>
      <pubDate>Mon, 23 Aug 2010 12:22:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-IF-Statement/m-p/66291#M6657</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-08-23T12:22:17Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with IF Statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-IF-Statement/m-p/66292#M6658</link>
      <description>i see,&lt;BR /&gt;
&lt;BR /&gt;
so what is the replacement for "isnull" in sas?&lt;BR /&gt;
&lt;BR /&gt;
Thanks,</description>
      <pubDate>Mon, 23 Aug 2010 13:11:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-IF-Statement/m-p/66292#M6658</guid>
      <dc:creator>thegraduate</dc:creator>
      <dc:date>2010-08-23T13:11:19Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with IF Statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-IF-Statement/m-p/66293#M6659</link>
      <description>RTFM.  "IS NULL" works in SQL, "IF" does not.  If you are in the data step, then the syntax is "= ." (numeric) or "= ' '" (character).</description>
      <pubDate>Mon, 23 Aug 2010 14:30:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-IF-Statement/m-p/66293#M6659</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2010-08-23T14:30:42Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with IF Statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-IF-Statement/m-p/66294#M6660</link>
      <description>so buy changing the IsNull to =" ", this will mean the statement will work?&lt;BR /&gt;
&lt;BR /&gt;
Thanks,</description>
      <pubDate>Mon, 23 Aug 2010 15:26:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-IF-Statement/m-p/66294#M6660</guid>
      <dc:creator>thegraduate</dc:creator>
      <dc:date>2010-08-23T15:26:05Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with IF Statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-IF-Statement/m-p/66295#M6661</link>
      <description>Hi:&lt;BR /&gt;
  It is generally useful if you post your WHOLE program...not just the bits where you have issues...and provide a bit of context. For example, if you tried to put an IF statement into the SQL query built by EG, I would not expect this to work at all. If you tried to put an IF statement into PROC SQL code in a code node, then I would not expect -that- to work either.&lt;BR /&gt;
&lt;BR /&gt;
  If you are writing a DATA step program and want to put an IF statement into a DATA step program, then you need to understand how SAS internally stores missing values and how the internal storage of missing values is different between SAS datasets and, an RDBMS (such as Oracle or DB2). This Tech Support note provides some background:&lt;BR /&gt;
&lt;A href="http://support.sas.com/kb/23/226.html" target="_blank"&gt;http://support.sas.com/kb/23/226.html&lt;/A&gt; and&lt;BR /&gt;
&lt;A href="http://support.sas.com/resources/papers/resultsets.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/resultsets.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
  For the documentation on working with SAS variables, this site has the basic concepts on missing values:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#/documentation/cdl/en/lrcon/62955/HTML/default/a001292604.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#/documentation/cdl/en/lrcon/62955/HTML/default/a001292604.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
  Without understanding more about how you're using your IF statement (PROC SQL or DATA step program), the only help that can be offered are suggestions to read the documentation and look for examples.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Mon, 23 Aug 2010 16:49:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-IF-Statement/m-p/66295#M6661</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-08-23T16:49:42Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with IF Statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-IF-Statement/m-p/66296#M6662</link>
      <description>I decided to do it via CASE statements, but still get an error. I have underlined and bolded where it finds an error. &lt;BR /&gt;
&lt;BR /&gt;
Statement:&lt;BR /&gt;
&lt;BR /&gt;
CASE WHEN t3.'6MthAvgPayTerms'n ="" Then 'N/A' ELSE CASE WHEN t2.Account_Status = 'Live' When t3.'6MthAvgPayTerms'n&amp;lt;=60 THEN 'Good' When t3.'6MthAvgPayTerms'n &amp;gt;60 And t3.'6MthAvgPayTerms'n &amp;lt;=90 THEN 'Indeterminate' WHEN t3.'6MthAvgPayTerms'n &amp;gt;90 THEN 'BAD' ELSE CASE When t2.Account_Status ='Final' WHEN t3.'6MthAvgPayTerms'n &amp;gt;=30 Or t2.Account_Balance &amp;gt;=50 Or t3.'6MthAvgPayTerms'n =-1 Or t2.Pending_WO=-1 Or t2.Litigation_Account =-1 Or t2.Trident_Account=-1 THEN 'BAD' WHEN t3.'6MthAvgPayTerms'n=0 THEN 'GOOD' WHEN t3.'6MthAvgPayTerms'n&amp;gt;=0 And t3.'6MthAvgPayTerms'n &amp;lt;30 THEN 'Indeterminate' ELSE 'N/A' end &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
42                   /* Good Bad 1 */&lt;BR /&gt;
43                     (CASE WHEN t3.'6MthAvgPayTerms'n ="" Then 'N/A' ELSE CASE WHEN t2.Account_Status = 'Live' &lt;U&gt;&lt;B&gt;When&lt;/B&gt;&lt;/U&gt; t3.&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, EQ, EQT, GE, GET, &lt;BR /&gt;
              GT, GTT, LE, LET, LT, LTT, NE, NET, NOT, OR, THEN, ^, ^=, |, ||, ~, ~=.  &lt;BR /&gt;
&lt;BR /&gt;
ERROR 76-322: Syntax error, statement will be ignored.&lt;BR /&gt;
&lt;BR /&gt;
44                     '6MthAvgPayTerms'n&amp;lt;=60 THEN 'Good' When t3.'6MthAvgPayTerms'n &amp;gt;60 And t3.'6MthAvgPayTerms'n &amp;lt;=90 THEN&lt;BR /&gt;
45                     'Indeterminate' WHEN t3.'6MthAvgPayTerms'n &amp;gt;90 THEN 'BAD' ELSE CASE When t2.Account_Status ='Final' WHEN t3.&lt;BR /&gt;
46                     '6MthAvgPayTerms'n &amp;gt;=30 Or t2.Account_Balance &amp;gt;=50 Or t3.'6MthAvgPayTerms'n =-1 Or t2.Pending_WO=-1 Or&lt;BR /&gt;
47                      t2.Litigation_Account =-1 Or t2.Trident_Account=-1 THEN 'BAD' WHEN t3.'6MthAvgPayTerms'n=0 THEN 'GOOD' WHEN&lt;BR /&gt;
2                                                          The SAS System                              14:10 Monday, August 23, 2010&lt;BR /&gt;
&lt;BR /&gt;
48                      t3.'6MthAvgPayTerms'n&amp;gt;=0 And t3.'6MthAvgPayTerms'n &amp;lt;30 THEN 'Indeterminate' ELSE 'N/A' end ) AS&lt;BR /&gt;
49                     'Good Bad 1'n

Message was edited by: thegraduate</description>
      <pubDate>Tue, 24 Aug 2010 09:13:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-IF-Statement/m-p/66296#M6662</guid>
      <dc:creator>thegraduate</dc:creator>
      <dc:date>2010-08-24T09:13:11Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with IF Statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-IF-Statement/m-p/66297#M6663</link>
      <description>Hi&lt;BR /&gt;
 &lt;BR /&gt;
markup for the forum uses some of the characters in your program so it isn't presented clearly&lt;BR /&gt;
  &lt;BR /&gt;
(I used "Quote Original" button on the message entry frame to display more of your message)&lt;BR /&gt;
 &lt;BR /&gt;
The area causing the error might be just after the good/bad comment.&lt;BR /&gt;
At that point the syntax appears to be &lt;BR /&gt;
[pre]&lt;BR /&gt;
       THEN 'Indeterminate' ELSE 'N/A' end  &lt;BR /&gt;
          /* Good Bad 1 */&lt;BR /&gt;
                  (CASE WHEN  t3.'6MthAvgPayTerms'n ="" &lt;BR /&gt;
                              Then 'N/A' &lt;BR /&gt;
                              ELSE &lt;BR /&gt;
                                   CASE WHEN [/pre]&lt;BR /&gt;
Your syntax seems to go from "end" to "(CASE" without anything in between.&lt;BR /&gt;
That looks like a mistake to me.&lt;BR /&gt;
I would expect at least the comma (between column definitions). However, the syntax still seems to be in the middle of CASE nesting.&lt;BR /&gt;
 &lt;BR /&gt;
If there is some way of (or somewhere to) upload the code so we could see the original syntax, we might be better able to avoid the forum-markup difficulties and make better informed judgements.&lt;BR /&gt;
 &lt;BR /&gt;
Forum markup explanations are at &lt;A href="http://support.sas.com/forums/thread.jspa?messageID=27609毙" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?messageID=27609毙&lt;/A&gt; &lt;BR /&gt;
 &lt;BR /&gt;
good luck&lt;BR /&gt;
peterC&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; t3.'6MthAvgPayTerms'n&amp;gt;=0 And t3.'6MthAvgPayTerms'n&lt;BR /&gt;
&amp;gt; &amp;lt;30 THEN 'Indeterminate' ELSE 'N/A' end &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; 42                   /* Good Bad 1 */&lt;BR /&gt;
&amp;gt; 43                     (CASE WHEN&lt;BR /&gt;
&amp;gt; t3.'6MthAvgPayTerms'n ="" Then 'N/A' ELSE CASE WHEN&lt;BR /&gt;
&amp;gt; t2.Account_Status = 'Live' &lt;U&gt;&lt;B&gt;When&lt;/B&gt;&lt;/U&gt; t3.&lt;BR /&gt;
&amp;gt;</description>
      <pubDate>Tue, 24 Aug 2010 12:17:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-IF-Statement/m-p/66297#M6663</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-08-24T12:17:49Z</dc:date>
    </item>
  </channel>
</rss>

