<?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 Multiple set operators in SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Multiple-set-operators-in-SQL/m-p/489008#M127544</link>
    <description>&lt;P&gt;I just want to double check my thinking on this...&amp;nbsp; When using multiple set operators in SQL in a single SQL statement, are the actions performed incrementally?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, I have in my code:&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;proc sql;
select distinct vv.naics_code
from eds.pt_naic_codes as vv

union

select distinct loc.naics_code 
from eds.pa_location as loc

union

select distinct qcew.naics_code_pt_naic_codes as naics_code
from eds.ps_qcew_data as qcew

except

select sched.naics_code
from eds.ps_scheduling_naics as sched;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and I want it to work so that it appends the first three tables before excluding the fourth table.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As written, will I be getting what I expect?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Aug 2018 18:59:38 GMT</pubDate>
    <dc:creator>TashaChapman14</dc:creator>
    <dc:date>2018-08-22T18:59:38Z</dc:date>
    <item>
      <title>Multiple set operators in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-set-operators-in-SQL/m-p/489008#M127544</link>
      <description>&lt;P&gt;I just want to double check my thinking on this...&amp;nbsp; When using multiple set operators in SQL in a single SQL statement, are the actions performed incrementally?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, I have in my code:&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;proc sql;
select distinct vv.naics_code
from eds.pt_naic_codes as vv

union

select distinct loc.naics_code 
from eds.pa_location as loc

union

select distinct qcew.naics_code_pt_naic_codes as naics_code
from eds.ps_qcew_data as qcew

except

select sched.naics_code
from eds.ps_scheduling_naics as sched;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and I want it to work so that it appends the first three tables before excluding the fourth table.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As written, will I be getting what I expect?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 18:59:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-set-operators-in-SQL/m-p/489008#M127544</guid>
      <dc:creator>TashaChapman14</dc:creator>
      <dc:date>2018-08-22T18:59:38Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple set operators in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-set-operators-in-SQL/m-p/489025#M127549</link>
      <description>&lt;P&gt;Parentheses may be your friend to help control "order".&lt;/P&gt;
&lt;P&gt;Perhaps:&lt;/P&gt;
&lt;PRE&gt;proc sql;
(
select distinct vv.naics_code
from eds.pt_naic_codes as vv

union

select distinct loc.naics_code 
from eds.pa_location as loc

union

select distinct qcew.naics_code_pt_naic_codes as naics_code
from eds.ps_qcew_data as qcew
)
except

select sched.naics_code
from eds.ps_scheduling_naics as sched;
quit;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Aug 2018 19:53:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-set-operators-in-SQL/m-p/489025#M127549</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-22T19:53:40Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple set operators in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-set-operators-in-SQL/m-p/489071#M127584</link>
      <description>&lt;P&gt;The most reliable place to look is the SAS documentation which says:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"&lt;EM&gt;A query expression with set operators is evaluated as follows.&lt;/EM&gt;&lt;/P&gt;
&lt;DIV class="xis-paragraph" id="p0zcweylzkojwmn1bzz70t393xf5"&gt;
&lt;DIV class="xis-listUnordered"&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;DIV class="xis-item" id="p06na8ufv6ecuyn1xfa9wsmofygq"&gt;
&lt;DIV class="xis-paraSimpleFirst" id="p0aaa61gfxszyvn1hkjy04z5pc8e"&gt;&lt;EM&gt;Each table expression is evaluated to produce an (internal) intermediate result table.&lt;/EM&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV class="xis-item" id="p1av6573w6s86fn156yr0p8uw37b"&gt;
&lt;DIV class="xis-paraSimpleFirst" id="p0k6yf10tb976dn1qsavverm9rph"&gt;&lt;EM&gt;Each intermediate result table then becomes an operand linked with a set operator to form an expression, for example, A UNION B.&lt;/EM&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV class="xis-item" id="p0ub8i5ihf26fdn1wfgxtd764qgq"&gt;
&lt;DIV class="xis-paraSimpleFirst" id="n1n29ln7wo452vn1vesn2iu5tj60"&gt;&lt;EM&gt;If the query expression involves more than two table expressions, then the result from the first two becomes an operand for the next set operator and operand, such as (A UNION B) EXCEPT C, ((A UNION B) EXCEPT C) INTERSECT D, and so on.&lt;/EM&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV class="xis-item" id="p1v79oyzh385lqn15h8dzwbuzcmn"&gt;
&lt;DIV class="xis-paraSimpleFirst" id="n1p65we60gcbi4n1kxnlq9m85uv5"&gt;&lt;EM&gt;Evaluating a query expression produces a single output table.&lt;/EM&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="xis-paragraph" id="n0iu1p86tadc6zn10xj3meesynp1"&gt;&lt;EM&gt;Set operators follow this order of precedence unless they are overridden by parentheses in the expressions: INTERSECT is evaluated first. OUTER UNION, UNION, and EXCEPT have the same level of precedence.&lt;/EM&gt;"&lt;/DIV&gt;
&lt;DIV class="xis-paragraph"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="xis-paragraph"&gt;So yes, the query will perform as you expect.&lt;/DIV&gt;
&lt;DIV class="xis-paragraph"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="xis-paragraph"&gt;Note that using the keyword ALL might improve performance a bit, if you don't need to remove duplicates.&lt;/DIV&gt;</description>
      <pubDate>Wed, 22 Aug 2018 22:09:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-set-operators-in-SQL/m-p/489071#M127584</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-08-22T22:09:48Z</dc:date>
    </item>
  </channel>
</rss>

