<?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: multiple where statement in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/multiple-where-statement/m-p/806215#M33537</link>
    <description>&lt;P&gt;&lt;STRONG&gt;Code formatting.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Code formatting.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Code formatting.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As long as you write ugly, unstructured code like this, you'll have trouble seeing the possible problems.&lt;/P&gt;
&lt;P&gt;And you can use the Enhanced Editor to detect the relationship of parentheses.&lt;/P&gt;
&lt;P&gt;After applying indentation according to the brackets, I get this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc sql ;
create table Test as
  select distinct
    debt_code,
    ResultType,
    datepart(tcfDateConfirmed) as Test_date format date9.,
    DateConfirmed as Test_dt format datetime20.,
    Description,
    t3.Portfolioid,
    t3.CaseflowPortfolioname,
    t3.Accountstatus,
    t3.Bookondate
    from (
      select
        t1.ReferenceNumber,
        t1.TraceResultType,
        t1.DateConfirmed,
        t2.Description
      from Trace.CaseFlowData as t1
      inner join Trace.ResultType as t2
      on ( t1.TraceResultType = t2.TypeID and t2.TraceSource ='Test' and t1.TracerID = 99)
      inner join Test_account as t3 on ReferenceNumber = t3.accountnumber
      Where 
        (t1.TimeStamp &amp;gt;= '01DEC2021:00:00:00'dt and t1.TimeStamp &amp;lt; '31DEC2021:00:00:00'dt) and
        t3.Bookondate &amp;gt;= '01DEC2021:00:00:00'dt and t3.Bookondate &amp;lt; '31DEC2021:00:00:00'dt 
    ) and
    t3.CaseflowPortfolioname like ('BT039', 'EDF058', 'EDF060', 'EDF059', 'BRITGAS129', 'EDF057', 'BRITGAS129')
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can see that a bracket terminates the sub-select, causing the rest of the WHERE condition to be invalid syntax.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I tried to correct your code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table Test as
  select distinct
    debt_code,
    ResultType,
    datepart(tcfDateConfirmed) as Test_date format date9.,
    DateConfirmed as Test_dt format datetime20.,
    Description,
    t3.Portfolioid,
    t3.CaseflowPortfolioname,
    t3.Accountstatus,
    t3.Bookondate
    from (
      select
        t1.ReferenceNumber,
        t1.TraceResultType,
        t1.DateConfirmed,
        t2.Description
      from Trace.CaseFlowData as t1
      inner join Trace.ResultType as t2
      on t1.TraceResultType = t2.TypeID and t2.TraceSource = 'Test' and t1.TracerID = 99
      inner join Test_account as t3 on ReferenceNumber = t3.accountnumber
      where 
        t1.TimeStamp &amp;gt;= '01DEC2021:00:00:00'dt and t1.TimeStamp &amp;lt; '31DEC2021:00:00:00'dt and
        t3.Bookondate &amp;gt;= '01DEC2021:00:00:00'dt and t3.Bookondate &amp;lt; '31DEC2021:00:00:00'dt and
        t3.CaseflowPortfolioname in ('BT039','EDF058','EDF060','EDF059','BRITGAS129','EDF057','BRITGAS129')
    )

;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;UL&gt;
&lt;LI&gt;correct placement of parentheses&lt;/LI&gt;
&lt;LI&gt;removed unnecessary parentheses (all your logical operators are AND)&lt;/LI&gt;
&lt;LI&gt;changed LIKE to IN&lt;/LI&gt;
&lt;LI&gt;ask yourself if DISTINCT is needed at all; having to do a sort of the result over all variables to detect doubles causes a massive (and usually unnecessary) load&lt;/LI&gt;
&lt;/UL&gt;</description>
    <pubDate>Wed, 06 Apr 2022 08:47:21 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-04-06T08:47:21Z</dc:date>
    <item>
      <title>multiple where statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/multiple-where-statement/m-p/806208#M33533</link>
      <description>&lt;P&gt;Hi, I am trying to add the names in the where statement but getting error.&lt;/P&gt;&lt;P&gt;Proc sql ;&lt;BR /&gt;create table Test as&lt;BR /&gt;select distinct&lt;/P&gt;&lt;P&gt;debt_code,&lt;BR /&gt;ResultType,&lt;BR /&gt;datepart(tcfDateConfirmed) as Test_date format date9.,&lt;BR /&gt;DateConfirmed as Test_dt format datetime20.,&lt;BR /&gt;Description,&lt;BR /&gt;t3.Portfolioid,&lt;BR /&gt;t3.CaseflowPortfolioname,&lt;BR /&gt;t3.Accountstatus,&lt;BR /&gt;t3.Bookondate&lt;BR /&gt;from&lt;BR /&gt;(select&lt;BR /&gt;t1.ReferenceNumber,&lt;BR /&gt;t1.TraceResultType,&lt;BR /&gt;t1.DateConfirmed,&lt;BR /&gt;t2.Description&lt;/P&gt;&lt;P&gt;from Trace.CaseFlowData as t1&lt;BR /&gt;inner join Trace.ResultType as t2 on ( t1.TraceResultType = t2.TypeID and t2.TraceSource ='Test' and t1.TracerID = 99)/&lt;BR /&gt;inner join Test_account as t3 on ReferenceNumber = t3.accountnumber&lt;/P&gt;&lt;P&gt;Where&lt;BR /&gt;(t1.TimeStamp &amp;gt;= '01DEC2021:00:00:00'dt and t1.TimeStamp &amp;lt; '31DEC2021:00:00:00'dt) and&lt;BR /&gt;t3.Bookondate &amp;gt;= '01DEC2021:00:00:00'dt and t3.Bookondate &amp;lt; '31DEC2021:00:00:00'dt) and&lt;BR /&gt;&lt;STRONG&gt;t3.CaseflowPortfolioname like ('BT039', 'EDF058', 'EDF060', 'EDF059', 'BRITGAS129', 'EDF057', 'BRITGAS129');&lt;/STRONG&gt;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I add the bold line in the where clause to get only these portfolionames, I am getting below error:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;54 from Trace.tCaseFlowDataAudit as t1&lt;BR /&gt;55 inner join Trace.tResultType as t2 on ( t1.TraceResultType = t2.TypeID and t2.TraceSource ='Test' and&lt;BR /&gt;55 ! t1.TracerID = 99)&lt;BR /&gt;56 inner join Test_account as t3 on ReferenceNumber = t3.accountnumber&lt;BR /&gt;57&lt;BR /&gt;58 Where&lt;BR /&gt;59 (t1.TimeStamp &amp;gt;= '01DEC2021:00:00:00'dt and t1.TimeStamp &amp;lt; '31DEC2021:00:00:00'dt) and&lt;BR /&gt;60 t3.CaseflowPortfolioname like ('BT039', 'EDF058', 'EDF060', 'EDF059', 'BRITGAS129', 'EDF057', 'BRITGAS129');&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;NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;BR /&gt;61 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;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2022 08:26:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/multiple-where-statement/m-p/806208#M33533</guid>
      <dc:creator>Sandeep77</dc:creator>
      <dc:date>2022-04-06T08:26:25Z</dc:date>
    </item>
    <item>
      <title>Re: multiple where statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/multiple-where-statement/m-p/806214#M33536</link>
      <description>&lt;P&gt;I also tried&amp;nbsp;&lt;STRONG&gt;t3.CaseflowPortfolioname IN ('BT039', 'EDF058', 'EDF060', 'EDF059', 'BRITGAS129', 'EDF057', 'BRITGAS129') &lt;/STRONG&gt;but getting same error.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2022 08:46:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/multiple-where-statement/m-p/806214#M33536</guid>
      <dc:creator>Sandeep77</dc:creator>
      <dc:date>2022-04-06T08:46:18Z</dc:date>
    </item>
    <item>
      <title>Re: multiple where statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/multiple-where-statement/m-p/806215#M33537</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Code formatting.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Code formatting.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Code formatting.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As long as you write ugly, unstructured code like this, you'll have trouble seeing the possible problems.&lt;/P&gt;
&lt;P&gt;And you can use the Enhanced Editor to detect the relationship of parentheses.&lt;/P&gt;
&lt;P&gt;After applying indentation according to the brackets, I get this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc sql ;
create table Test as
  select distinct
    debt_code,
    ResultType,
    datepart(tcfDateConfirmed) as Test_date format date9.,
    DateConfirmed as Test_dt format datetime20.,
    Description,
    t3.Portfolioid,
    t3.CaseflowPortfolioname,
    t3.Accountstatus,
    t3.Bookondate
    from (
      select
        t1.ReferenceNumber,
        t1.TraceResultType,
        t1.DateConfirmed,
        t2.Description
      from Trace.CaseFlowData as t1
      inner join Trace.ResultType as t2
      on ( t1.TraceResultType = t2.TypeID and t2.TraceSource ='Test' and t1.TracerID = 99)
      inner join Test_account as t3 on ReferenceNumber = t3.accountnumber
      Where 
        (t1.TimeStamp &amp;gt;= '01DEC2021:00:00:00'dt and t1.TimeStamp &amp;lt; '31DEC2021:00:00:00'dt) and
        t3.Bookondate &amp;gt;= '01DEC2021:00:00:00'dt and t3.Bookondate &amp;lt; '31DEC2021:00:00:00'dt 
    ) and
    t3.CaseflowPortfolioname like ('BT039', 'EDF058', 'EDF060', 'EDF059', 'BRITGAS129', 'EDF057', 'BRITGAS129')
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can see that a bracket terminates the sub-select, causing the rest of the WHERE condition to be invalid syntax.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I tried to correct your code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table Test as
  select distinct
    debt_code,
    ResultType,
    datepart(tcfDateConfirmed) as Test_date format date9.,
    DateConfirmed as Test_dt format datetime20.,
    Description,
    t3.Portfolioid,
    t3.CaseflowPortfolioname,
    t3.Accountstatus,
    t3.Bookondate
    from (
      select
        t1.ReferenceNumber,
        t1.TraceResultType,
        t1.DateConfirmed,
        t2.Description
      from Trace.CaseFlowData as t1
      inner join Trace.ResultType as t2
      on t1.TraceResultType = t2.TypeID and t2.TraceSource = 'Test' and t1.TracerID = 99
      inner join Test_account as t3 on ReferenceNumber = t3.accountnumber
      where 
        t1.TimeStamp &amp;gt;= '01DEC2021:00:00:00'dt and t1.TimeStamp &amp;lt; '31DEC2021:00:00:00'dt and
        t3.Bookondate &amp;gt;= '01DEC2021:00:00:00'dt and t3.Bookondate &amp;lt; '31DEC2021:00:00:00'dt and
        t3.CaseflowPortfolioname in ('BT039','EDF058','EDF060','EDF059','BRITGAS129','EDF057','BRITGAS129')
    )

;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;UL&gt;
&lt;LI&gt;correct placement of parentheses&lt;/LI&gt;
&lt;LI&gt;removed unnecessary parentheses (all your logical operators are AND)&lt;/LI&gt;
&lt;LI&gt;changed LIKE to IN&lt;/LI&gt;
&lt;LI&gt;ask yourself if DISTINCT is needed at all; having to do a sort of the result over all variables to detect doubles causes a massive (and usually unnecessary) load&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Wed, 06 Apr 2022 08:47:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/multiple-where-statement/m-p/806215#M33537</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-06T08:47:21Z</dc:date>
    </item>
    <item>
      <title>Re: multiple where statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/multiple-where-statement/m-p/806219#M33539</link>
      <description>Thank you</description>
      <pubDate>Wed, 06 Apr 2022 08:54:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/multiple-where-statement/m-p/806219#M33539</guid>
      <dc:creator>Sandeep77</dc:creator>
      <dc:date>2022-04-06T08:54:05Z</dc:date>
    </item>
  </channel>
</rss>

