<?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 proc sql unexpected result of nested intersection/except in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-unexpected-result-of-nested-intersection-except/m-p/876331#M82736</link>
    <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;I am a newbie in SAS, but faced with unexpected behavior of intersection/except nested in select&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Consider 2 datasets m and n&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data m;
input x$ @@;
cards;
a b e
;
run;

data n;
input x$ @@;
cards;
a d e
;
run;&lt;/PRE&gt;&lt;P&gt;The following query with IN gives the expected result 'd'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;&lt;BR /&gt;SELECT * FROM n&lt;BR /&gt;WHERE x IN (SELECT * FROM n&lt;BR /&gt;            EXCEPT &lt;BR /&gt;           SELECT * FROM m);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Unlike the query with EQUAL instead of IN, which returns 'e'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;
SELECT * FROM n
WHERE x EQUAL (SELECT * FROM n
            EXCEPT 
           SELECT * FROM m);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Can anybody explain such strange behavior? I would really appreciate your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can give more examples, in case they are needed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 17 May 2023 21:39:32 GMT</pubDate>
    <dc:creator>Nick347</dc:creator>
    <dc:date>2023-05-17T21:39:32Z</dc:date>
    <item>
      <title>proc sql unexpected result of nested intersection/except</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-unexpected-result-of-nested-intersection-except/m-p/876331#M82736</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;I am a newbie in SAS, but faced with unexpected behavior of intersection/except nested in select&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Consider 2 datasets m and n&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data m;
input x$ @@;
cards;
a b e
;
run;

data n;
input x$ @@;
cards;
a d e
;
run;&lt;/PRE&gt;&lt;P&gt;The following query with IN gives the expected result 'd'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;&lt;BR /&gt;SELECT * FROM n&lt;BR /&gt;WHERE x IN (SELECT * FROM n&lt;BR /&gt;            EXCEPT &lt;BR /&gt;           SELECT * FROM m);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Unlike the query with EQUAL instead of IN, which returns 'e'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;
SELECT * FROM n
WHERE x EQUAL (SELECT * FROM n
            EXCEPT 
           SELECT * FROM m);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Can anybody explain such strange behavior? I would really appreciate your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can give more examples, in case they are needed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 May 2023 21:39:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-unexpected-result-of-nested-intersection-except/m-p/876331#M82736</guid>
      <dc:creator>Nick347</dc:creator>
      <dc:date>2023-05-17T21:39:32Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql unexpected result of nested intersection/except</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-unexpected-result-of-nested-intersection-except/m-p/876332#M82737</link>
      <description>&lt;P&gt;How can a single value be equal to a SET?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The real question is why doesn't PROC SQL generate an error when given an impossible query.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 May 2023 21:52:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-unexpected-result-of-nested-intersection-except/m-p/876332#M82737</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-17T21:52:08Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql unexpected result of nested intersection/except</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-unexpected-result-of-nested-intersection-except/m-p/876339#M82738</link>
      <description>&lt;P&gt;Goes it mean that it is invalid to call SELECT query after EQUAL operator even if the SELECT is going to return a single value?&lt;/P&gt;</description>
      <pubDate>Wed, 17 May 2023 22:31:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-unexpected-result-of-nested-intersection-except/m-p/876339#M82738</guid>
      <dc:creator>Nick347</dc:creator>
      <dc:date>2023-05-17T22:31:28Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql unexpected result of nested intersection/except</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-unexpected-result-of-nested-intersection-except/m-p/876345#M82739</link>
      <description>&lt;P&gt;First thing is that there is no EQUAL operator.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It only ran because you can use EQ as a replacement for the = operator and SAS will assume you meant EQ.&lt;/P&gt;
&lt;PRE&gt;31   proc sql;
32   select name,age,age equal 10 as age2
                         -----
                         1
WARNING 1-322: Assuming the symbol EQ was misspelled as equal.

33   from sashelp.class
34   ;
&lt;/PRE&gt;
&lt;P&gt;In theory you can use a select in that way, it is just not a very useful tool.&lt;/P&gt;
&lt;P&gt;You have to absolutely positive that it will only return one observation.&amp;nbsp; Otherwise you get this error message&lt;/P&gt;
&lt;PRE&gt;103  proc sql;
104  select name, (select age from sashelp.class ) as age
105  from sashelp.class
106  ;
ERROR: Subquery evaluated to more than one row.
&lt;/PRE&gt;
&lt;P&gt;And only one variable. Otherwise you get this error message&lt;/P&gt;
&lt;PRE&gt;107  proc sql;
108  select name, (select age,height from sashelp.class where name='Alice' ) as age
109  from sashelp.class
110  ;
ERROR: A Composite expression (usually a subquery) is used incorrectly in an expression.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;It does seem that trying to use that particular EXCEPT query in that way does not work properly.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;You probably would need to open a ticket with SAS Support to get an explanation of what is going wrong.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 17 May 2023 22:51:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-unexpected-result-of-nested-intersection-except/m-p/876345#M82739</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-17T22:51:13Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql unexpected result of nested intersection/except</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-unexpected-result-of-nested-intersection-except/m-p/876366#M82740</link>
      <description>&lt;P&gt;Thank you so much for your help, I will follow your advise regarding a ticket.&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2023 05:57:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-unexpected-result-of-nested-intersection-except/m-p/876366#M82740</guid>
      <dc:creator>Nick347</dc:creator>
      <dc:date>2023-05-18T05:57:16Z</dc:date>
    </item>
  </channel>
</rss>

