<?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: Correlated Subquery Capability Compared to SQL Server in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-Correlated-Subquery-Capability-Compared-to-SQL-Server/m-p/421306#M67960</link>
    <description>&lt;P&gt;Hi folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Quick question about correlated subqueries in PROC SQL. I am curious whether a specific functionality that exists in Microsoft's SQL Server's T-SQL also exists in PROC SQL.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please see queries below. Query #1, involving a simple join, works the same way in both PROC SQL and SQL Server's T-SQL.&amp;nbsp;Query #2, though, which uses a correlated subquery in the SELECT clause , works fine in SQL Server's T-SQL but &lt;U&gt;not&lt;/U&gt; in PROC SQL.&amp;nbsp; Would you know whether this type of correlated subquery (i.e., &lt;U&gt;one that is&amp;nbsp;embedded within the SELECT&amp;nbsp;clause&lt;/U&gt;) is possible in PROC SQL? If so, what might the syntax look like?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance for your help. And &lt;STRONG&gt;please&lt;/STRONG&gt;, I already know this is a non-standard thing to do&amp;nbsp;and is highly inefficient. I'm just curious whether the functionality exists in PROC SQL. There are situations where it is very useful. Thanks again!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" size="1 2 3 4 5 6 7"&gt;PROC SQL;&lt;BR /&gt;
&lt;FONT color="#0000FF"&gt;    *---- create some play data -------------------------------------*;&lt;/FONT&gt;
    CREATE TABLE &lt;FONT color="#0000FF"&gt;table1&lt;/FONT&gt; (ID INT, FirstName CHAR(12));
    INSERT INTO table1 (ID, FirstName) VALUES (1, "Tom" );
    INSERT INTO table1 (ID, FirstName) VALUES (2, "Richard" );
    INSERT INTO table1 (ID, FirstName) VALUES (3, "Harry");

    CREATE TABLE &lt;FONT color="#0000FF"&gt;table2&lt;/FONT&gt; (ID INT, City CHAR(12));&lt;BR /&gt;    INSERT INTO table2 (ID, City) VALUES (1, "Tampa");
    INSERT INTO table2 (ID, City) VALUES (2, "Boston");
    INSERT INTO table2 (ID, City) VALUES (3, "Miami" );
&lt;FONT color="#0000FF"&gt;    *----------------------------------------------------------------*;&lt;/FONT&gt;
&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;    *----------------------------------------------------------------*;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;    *Query #1 -- this works the same in both PROC SQL and SQL Server's T-SQL;&lt;/FONT&gt;    &lt;BR /&gt;    SELECT    table1.ID,
              table1.FirstName,
              table2.City AS HomeTown

    FROM      table1
    LEFT JOIN table2 ON table1.ID=table2.ID;
&lt;FONT color="#0000FF"&gt;    *----------------------------------------------------------------*;&lt;/FONT&gt;
    *Query #2 -- This works in SQL Server's T-SQL but &lt;U&gt;&lt;FONT color="#0000FF"&gt;not&lt;/FONT&gt;&lt;/U&gt; in PROC SQL;
    SELECT    table1.ID,
              table1.FirstName,
              &lt;FONT color="#0000FF"&gt;HomeTown = (SELECT City FROM table2 WHERE table2.ID=table1.ID)&lt;/FONT&gt;

    FROM      table1;
&lt;FONT color="#0000FF"&gt;    *----------------------------------------------------------------*;&lt;/FONT&gt; 
QUIT;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 14 Dec 2017 19:07:48 GMT</pubDate>
    <dc:creator>twhite</dc:creator>
    <dc:date>2017-12-14T19:07:48Z</dc:date>
    <item>
      <title>PROC SQL: Correlated Subquery Capability Compared to SQL Server</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-Correlated-Subquery-Capability-Compared-to-SQL-Server/m-p/421306#M67960</link>
      <description>&lt;P&gt;Hi folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Quick question about correlated subqueries in PROC SQL. I am curious whether a specific functionality that exists in Microsoft's SQL Server's T-SQL also exists in PROC SQL.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please see queries below. Query #1, involving a simple join, works the same way in both PROC SQL and SQL Server's T-SQL.&amp;nbsp;Query #2, though, which uses a correlated subquery in the SELECT clause , works fine in SQL Server's T-SQL but &lt;U&gt;not&lt;/U&gt; in PROC SQL.&amp;nbsp; Would you know whether this type of correlated subquery (i.e., &lt;U&gt;one that is&amp;nbsp;embedded within the SELECT&amp;nbsp;clause&lt;/U&gt;) is possible in PROC SQL? If so, what might the syntax look like?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance for your help. And &lt;STRONG&gt;please&lt;/STRONG&gt;, I already know this is a non-standard thing to do&amp;nbsp;and is highly inefficient. I'm just curious whether the functionality exists in PROC SQL. There are situations where it is very useful. Thanks again!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" size="1 2 3 4 5 6 7"&gt;PROC SQL;&lt;BR /&gt;
&lt;FONT color="#0000FF"&gt;    *---- create some play data -------------------------------------*;&lt;/FONT&gt;
    CREATE TABLE &lt;FONT color="#0000FF"&gt;table1&lt;/FONT&gt; (ID INT, FirstName CHAR(12));
    INSERT INTO table1 (ID, FirstName) VALUES (1, "Tom" );
    INSERT INTO table1 (ID, FirstName) VALUES (2, "Richard" );
    INSERT INTO table1 (ID, FirstName) VALUES (3, "Harry");

    CREATE TABLE &lt;FONT color="#0000FF"&gt;table2&lt;/FONT&gt; (ID INT, City CHAR(12));&lt;BR /&gt;    INSERT INTO table2 (ID, City) VALUES (1, "Tampa");
    INSERT INTO table2 (ID, City) VALUES (2, "Boston");
    INSERT INTO table2 (ID, City) VALUES (3, "Miami" );
&lt;FONT color="#0000FF"&gt;    *----------------------------------------------------------------*;&lt;/FONT&gt;
&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;    *----------------------------------------------------------------*;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;    *Query #1 -- this works the same in both PROC SQL and SQL Server's T-SQL;&lt;/FONT&gt;    &lt;BR /&gt;    SELECT    table1.ID,
              table1.FirstName,
              table2.City AS HomeTown

    FROM      table1
    LEFT JOIN table2 ON table1.ID=table2.ID;
&lt;FONT color="#0000FF"&gt;    *----------------------------------------------------------------*;&lt;/FONT&gt;
    *Query #2 -- This works in SQL Server's T-SQL but &lt;U&gt;&lt;FONT color="#0000FF"&gt;not&lt;/FONT&gt;&lt;/U&gt; in PROC SQL;
    SELECT    table1.ID,
              table1.FirstName,
              &lt;FONT color="#0000FF"&gt;HomeTown = (SELECT City FROM table2 WHERE table2.ID=table1.ID)&lt;/FONT&gt;

    FROM      table1;
&lt;FONT color="#0000FF"&gt;    *----------------------------------------------------------------*;&lt;/FONT&gt; 
QUIT;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2017 19:07:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-Correlated-Subquery-Capability-Compared-to-SQL-Server/m-p/421306#M67960</guid>
      <dc:creator>twhite</dc:creator>
      <dc:date>2017-12-14T19:07:48Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL: Correlated Subquery Capability Compared to SQL Server</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-Correlated-Subquery-Capability-Compared-to-SQL-Server/m-p/421757#M67987</link>
      <description>&lt;P&gt;In SAS SQL you can do something similar using the UPDATE statement:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/kb/25/216.html" target="_blank"&gt;http://support.sas.com/kb/25/216.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The SQL Server example looks like an enhancement that is not ANSI standard, whereas the SAS example is.&lt;/P&gt;</description>
      <pubDate>Sat, 16 Dec 2017 08:46:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-Correlated-Subquery-Capability-Compared-to-SQL-Server/m-p/421757#M67987</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2017-12-16T08:46:55Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL: Correlated Subquery Capability Compared to SQL Server</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-Correlated-Subquery-Capability-Compared-to-SQL-Server/m-p/421772#M67988</link>
      <description>&lt;P&gt;That's right, in SAS SQL you have to do it as&lt;/P&gt;&lt;PRE&gt;    SELECT    table1.ID,
              table1.FirstName,
              (SELECT City FROM table2 WHERE table2.ID=table1.ID) as Hometown
    FROM      table1;&lt;/PRE&gt;&lt;P&gt;which I think is more correct SQL anyway.&lt;/P&gt;</description>
      <pubDate>Sat, 16 Dec 2017 11:09:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-Correlated-Subquery-Capability-Compared-to-SQL-Server/m-p/421772#M67988</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2017-12-16T11:09:41Z</dc:date>
    </item>
  </channel>
</rss>

