<?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: PROC SQL subqueries in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-subqueries/m-p/561560#M157235</link>
    <description>&lt;P&gt;the difference is control over what element populated the results table.&lt;/P&gt;
&lt;P&gt;did b over write a?&lt;/P&gt;
&lt;P&gt;do I want the value of a or b?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 25 May 2019 14:16:09 GMT</pubDate>
    <dc:creator>VDD</dc:creator>
    <dc:date>2019-05-25T14:16:09Z</dc:date>
    <item>
      <title>PROC SQL subqueries</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-subqueries/m-p/561535#M157218</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am learning PROC SQL in more detail.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the given example subquery:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
        select empid, lastname, firstname, city, state
           from sasuser.staffmaster
           where empid in
              (select empid
                 from sasuser.payrollmaster
                 where month(dateofbirth)=2);
quit ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I wrote what I thought was the equivalent using Join:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	select 
	 	empid, lastname, firstname, city, state
	from 
		sassuer.staffmaster as a
		inner join sasuser.payrollmaster as b
		where month(dateofbirth)=2 
	on a.empid = b.empid ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;[1] Is the correct?&lt;/P&gt;&lt;P&gt;[2] if so, what is the benefit to using subqueries?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Sat, 25 May 2019 05:33:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-subqueries/m-p/561535#M157218</guid>
      <dc:creator>mglogan</dc:creator>
      <dc:date>2019-05-25T05:33:41Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL subqueries</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-subqueries/m-p/561540#M157220</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/155121"&gt;@mglogan&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's say you have in table&amp;nbsp;sasuser.staffmaster one row with empid=1 and in table&amp;nbsp;sasuser.payrollmaster five rows with empid=1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With your code:&lt;/P&gt;
&lt;P&gt;The inner join will return 5 rows, the subquery will return 1 row&amp;nbsp; ...also investigate what EXISTS can do for you.&lt;/P&gt;</description>
      <pubDate>Sat, 25 May 2019 06:34:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-subqueries/m-p/561540#M157220</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-05-25T06:34:44Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL subqueries</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-subqueries/m-p/561543#M157222</link>
      <description>&lt;P&gt;1) There are a few things wrong with your code.. EmpId is in both tables, so you have to reference one of them. Also, you have a typo in a libref.&amp;nbsp;&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 
	 	a.empid, 
      lastname, 
      firstname, 
      city, 
      state
	from 
		sasuser.staffmaster as a
	inner join sasuser.payrollmaster as b
		on month(dateofbirth)=2 
	and a.empid = b.empid ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;2)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think this will help you:&amp;nbsp;&lt;A href="https://documentation.sas.com/?docsetId=sqlproc&amp;amp;docsetTarget=n1dvk6nw2jgit3n1wp3xf9q3fkvv.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;When to Use Joins and Subqueries&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 25 May 2019 07:05:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-subqueries/m-p/561543#M157222</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-05-25T07:05:08Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL subqueries</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-subqueries/m-p/561560#M157235</link>
      <description>&lt;P&gt;the difference is control over what element populated the results table.&lt;/P&gt;
&lt;P&gt;did b over write a?&lt;/P&gt;
&lt;P&gt;do I want the value of a or b?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 May 2019 14:16:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-subqueries/m-p/561560#M157235</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2019-05-25T14:16:09Z</dc:date>
    </item>
  </channel>
</rss>

