<?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: Syntax error multiple conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Syntax-error-multiple-conditions/m-p/678694#M204876</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql;
    select id,name,
        (case 
            when Alloc=0 then . 
            when Alloc=1 and Cal_Mon=REPORTING_DT then  
            Quar_Prem*Paid_Expenses
            when (Alloc=1 and Cal_Mon&amp;gt;=REPORTING_DT) then 
            ((Quar_Prem*sum(Expenses,actor)))
            else . 
        end)
    as Expense length = 8
        format = 21.4
    from have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 22 Aug 2020 19:30:35 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2020-08-22T19:30:35Z</dc:date>
    <item>
      <title>Syntax error multiple conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Syntax-error-multiple-conditions/m-p/678690#M204872</link>
      <description>&lt;P&gt;I'm looking for some help to resolve the below Syntax error. Tried placing the paranthesis in different places but it didn't help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code which I used is,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
    select id,name,
        (case 
            when Alloc=0 then . 
            else if (Alloc=1 and Cal_Mon=REPORTING_DT) then  
            ((Quar_Prem*Paid_Expenses))
            else if  (Alloc=1 and Cal_Mon&amp;gt;=REPORTING_DT) then 
            ((Quar_Prem*sum(Expenses+actor)))
            else . 
        end)
    as Expense length = 8
        format = 21.4
    from have;
quit;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;26         proc sql;
27             select id,name,
28                 (case
29                     when Alloc=0 then .
30                     else if (Alloc=1 and Cal_Mon=REPORTING_DT) then
                                                                  ____
                                                                  22
                                                                  76
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, 
              CONTAINS, EQ, EQT, GE, GET, GT, GTT, LE, LET, LIKE, LT, LTT, NE, NET, OR, ^=, |, ||, ~=.  

ERROR 76-322: Syntax error, statement will be ignored.

31                     ((Quar_Prem*Paid_Expenses))
32                     else if  (Alloc=1 and Cal_Mon&amp;gt;=REPORTING_DT) then
33                     ((Quar_Prem*sum(Expenses+actor)))
34                     else .
35                 end)
36             as Expense length = 8
37                 format = 21.4
38             from have;
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
39         quit;
NOTE: The SAS System stopped processing this step because of errors&lt;/PRE&gt;</description>
      <pubDate>Sat, 22 Aug 2020 18:50:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Syntax-error-multiple-conditions/m-p/678690#M204872</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2020-08-22T18:50:02Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax error multiple conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Syntax-error-multiple-conditions/m-p/678691#M204873</link>
      <description>&lt;P&gt;SQL does not know IF-THEN-ELSE, you have to use CASE-WHEN-&amp;lt;WHEN-&amp;gt;ELSE-END for every condition.&lt;/P&gt;</description>
      <pubDate>Sat, 22 Aug 2020 18:57:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Syntax-error-multiple-conditions/m-p/678691#M204873</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-22T18:57:48Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax error multiple conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Syntax-error-multiple-conditions/m-p/678692#M204874</link>
      <description>Thank you for letting me know. How to tackle with parenthesis? May I&lt;BR /&gt;request to check the whether the parenthesis are placed correctly in the&lt;BR /&gt;posted example?&lt;BR /&gt;</description>
      <pubDate>Sat, 22 Aug 2020 19:18:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Syntax-error-multiple-conditions/m-p/678692#M204874</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2020-08-22T19:18:21Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax error multiple conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Syntax-error-multiple-conditions/m-p/678693#M204875</link>
      <description>&lt;P&gt;Just use more WHEN clauses.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select id
     , name
     , case when (Alloc=0) then . 
            when (Alloc=1 and Cal_Mon=REPORTING_DT) then Quar_Prem*Paid_Expenses
            when (Alloc=1 and Cal_Mon&amp;gt;=REPORTING_DT) then Quar_Prem*sum(Expenses+actor)
            else . 
       end as Expense format = 21.4
from have
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What is that last value supposed to be?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Quar_Prem*sum(Expenses+actor)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Does EXPENSES or ACTOR ever have missing values?&amp;nbsp; Did you want to use SAS's SUM(,) function so that missing values are ignored?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Quar_Prem*sum(sum(Expenses,actor))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You don't have any group by, did you really want to use the aggregate sum of the addition of those two variables over the whole dataset so that the multiplying factor on each observation is the same? Did you want to add a GROUP BY clause so the multiplying factor is just constant for the observations in the same group?&lt;/P&gt;
&lt;P&gt;Or did you want to remove the SQL aggregate SUM() function so that there is a different multiplying factor on each observation?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Aug 2020 19:30:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Syntax-error-multiple-conditions/m-p/678693#M204875</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-08-22T19:30:46Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax error multiple conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Syntax-error-multiple-conditions/m-p/678694#M204876</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql;
    select id,name,
        (case 
            when Alloc=0 then . 
            when Alloc=1 and Cal_Mon=REPORTING_DT then  
            Quar_Prem*Paid_Expenses
            when (Alloc=1 and Cal_Mon&amp;gt;=REPORTING_DT) then 
            ((Quar_Prem*sum(Expenses,actor)))
            else . 
        end)
    as Expense length = 8
        format = 21.4
    from have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 22 Aug 2020 19:30:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Syntax-error-multiple-conditions/m-p/678694#M204876</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-08-22T19:30:35Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax error multiple conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Syntax-error-multiple-conditions/m-p/678698#M204879</link>
      <description>You used IF but SQL wants WHEN instead. That's the primary cause of your mistake, not parenthesis.</description>
      <pubDate>Sat, 22 Aug 2020 21:15:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Syntax-error-multiple-conditions/m-p/678698#M204879</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-08-22T21:15:57Z</dc:date>
    </item>
  </channel>
</rss>

