<?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 returning more rows than expected in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-returning-more-rows-than-expected/m-p/591723#M169569</link>
    <description>Thank you so much PG! I was thinking of using a data step merge, but would require a proc sort dedup as well as a lot of renaming and sorting, while this can be achieved in SQL in one step.</description>
    <pubDate>Wed, 25 Sep 2019 21:48:49 GMT</pubDate>
    <dc:creator>aaronh</dc:creator>
    <dc:date>2019-09-25T21:48:49Z</dc:date>
    <item>
      <title>proc sql returning more rows than expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-returning-more-rows-than-expected/m-p/591706#M169562</link>
      <description>&lt;P&gt;Hello experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I have a dataset X that I want to subset based on the key values stored in dataset Y:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table test as
select x.*
from x, y
where x.key1 = y.key1 and &lt;BR /&gt;      x.key2 = y.key2;
quit;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, when the proc sql completes running, I noticed that TEST dataset had almost twice as many rows as X. So I am wondering why this is happening and what alternatives are there?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To give you an example of what I am trying to achieve: say X has 'apple' and 'banana' under key1, but Y only has 'banana' under key1, how do I make sure the subset of X only has banana for key1?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2019 21:12:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-returning-more-rows-than-expected/m-p/591706#M169562</guid>
      <dc:creator>aaronh</dc:creator>
      <dc:date>2019-09-25T21:12:43Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql returning more rows than expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-returning-more-rows-than-expected/m-p/591712#M169565</link>
      <description>&lt;P&gt;You must make sure that there are no duplicates of key1-key2 pairs in table y. Can be done with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table test as
select x.*
from x, (select distinct key1, key2 from y) as yy
where x.key1 = yy.key1 and  x.key2 = yy.key2;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Sep 2019 21:25:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-returning-more-rows-than-expected/m-p/591712#M169565</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-09-25T21:25:54Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql returning more rows than expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-returning-more-rows-than-expected/m-p/591723#M169569</link>
      <description>Thank you so much PG! I was thinking of using a data step merge, but would require a proc sort dedup as well as a lot of renaming and sorting, while this can be achieved in SQL in one step.</description>
      <pubDate>Wed, 25 Sep 2019 21:48:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-returning-more-rows-than-expected/m-p/591723#M169569</guid>
      <dc:creator>aaronh</dc:creator>
      <dc:date>2019-09-25T21:48:49Z</dc:date>
    </item>
  </channel>
</rss>

