<?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: How do I select everything with 2 tables that have 1 common ID using PROC SQL? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-select-everything-with-2-tables-that-have-1-common-ID/m-p/906635#M40505</link>
    <description>&lt;P&gt;Please do not confuse data step MERGE with any of the joins. It does several things quite differently than any of the joins.&lt;/P&gt;
&lt;P&gt;If a data step merge works for you then use that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your given join in Proc SQL is a Cartesian Join, meaning you would get every value of id that matches so that if you had Id=1 2 times in One and 3 times in Two you would get 6 output lines. Is that what you want?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest that you go back to your example data and show example with multiple observations with the same id and then desired/expected output. Provide that example data in the form of data step code pasted into a text box such as:&lt;/P&gt;
&lt;PRE&gt;Data One;
   input ID x $;
datalines;
1   a
2  b
;

data two;
  input ID y $;
datalines;
1   A
3  C
;&lt;/PRE&gt;
&lt;P&gt;The desired output should be shown in a similar fashion.&lt;/P&gt;</description>
    <pubDate>Wed, 06 Dec 2023 23:39:25 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-12-06T23:39:25Z</dc:date>
    <item>
      <title>How do I select everything with 2 tables that have 1 common ID using PROC SQL?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-select-everything-with-2-tables-that-have-1-common-ID/m-p/906610#M40503</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry the Subject may be confusing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's say I have two tables:&lt;/P&gt;
&lt;P&gt;Table One:&lt;/P&gt;
&lt;P&gt;ID x&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; a&lt;/P&gt;
&lt;P&gt;2 &amp;nbsp;b&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Table Two:&lt;/P&gt;
&lt;P&gt;ID y&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; A&lt;/P&gt;
&lt;P&gt;3 &amp;nbsp;C&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;&lt;BR /&gt;  create table want as
  select *
  from TableOne as One, TableTwo as Two&lt;BR /&gt;  where One.ID = Two.ID;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Desired output:&lt;BR /&gt;1 a A&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The above code will work but will give a WARNING and use the ID from TableOne. The correct version would be changing the SELECT statement to:&lt;/P&gt;
&lt;P&gt;select One.ID, x, y&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, the solution only works if there's 2 variables to list. What if there are hundreds? I know it can be done using a MERGE but is there a way to write it in PROC SQL?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Dec 2023 20:43:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-select-everything-with-2-tables-that-have-1-common-ID/m-p/906610#M40503</guid>
      <dc:creator>cosmid</dc:creator>
      <dc:date>2023-12-06T20:43:10Z</dc:date>
    </item>
    <item>
      <title>Re: How do I select everything with 2 tables that have 1 common ID using PROC SQL?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-select-everything-with-2-tables-that-have-1-common-ID/m-p/906635#M40505</link>
      <description>&lt;P&gt;Please do not confuse data step MERGE with any of the joins. It does several things quite differently than any of the joins.&lt;/P&gt;
&lt;P&gt;If a data step merge works for you then use that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your given join in Proc SQL is a Cartesian Join, meaning you would get every value of id that matches so that if you had Id=1 2 times in One and 3 times in Two you would get 6 output lines. Is that what you want?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest that you go back to your example data and show example with multiple observations with the same id and then desired/expected output. Provide that example data in the form of data step code pasted into a text box such as:&lt;/P&gt;
&lt;PRE&gt;Data One;
   input ID x $;
datalines;
1   a
2  b
;

data two;
  input ID y $;
datalines;
1   A
3  C
;&lt;/PRE&gt;
&lt;P&gt;The desired output should be shown in a similar fashion.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Dec 2023 23:39:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-select-everything-with-2-tables-that-have-1-common-ID/m-p/906635#M40505</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-12-06T23:39:25Z</dc:date>
    </item>
    <item>
      <title>Re: How do I select everything with 2 tables that have 1 common ID using PROC SQL?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-select-everything-with-2-tables-that-have-1-common-ID/m-p/906641#M40506</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;Your given join in Proc SQL is a Cartesian Join, meaning you would get every value of id that matches so that if you had Id=1 2 times in One and 3 times in Two you would get 6 output lines. Is that what you want?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;I believe you missed the where clause. This is an equijoin.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Dec 2023 00:28:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-select-everything-with-2-tables-that-have-1-common-ID/m-p/906641#M40506</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-12-07T00:28:32Z</dc:date>
    </item>
    <item>
      <title>Re: How do I select everything with 2 tables that have 1 common ID using PROC SQL?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-select-everything-with-2-tables-that-have-1-common-ID/m-p/906642#M40507</link>
      <description>&lt;P&gt;You cannot create a DATASET with two variables named ID.&amp;nbsp; That is why you only get one variable.&amp;nbsp; Does not really have anything to do with PROC SQL or SQL syntax per se.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you really need a dataset?&amp;nbsp; If you just want a REPORT then just drop the CREATE TABLE part of the query and it will execute.&amp;nbsp; &amp;nbsp;You could use ODS EXCEL to send the report to a file you could browse in a tabular fashion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But unless you either change the data or the code It won't return anything because 'a' does NOT equal 'A'.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Dec 2023 00:39:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-select-everything-with-2-tables-that-have-1-common-ID/m-p/906642#M40507</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-07T00:39:41Z</dc:date>
    </item>
    <item>
      <title>Re: How do I select everything with 2 tables that have 1 common ID using PROC SQL?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-select-everything-with-2-tables-that-have-1-common-ID/m-p/906721#M40513</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;Your given join in Proc SQL is a Cartesian Join, meaning you would get every value of id that matches so that if you had Id=1 2 times in One and 3 times in Two you would get 6 output lines. Is that what you want?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;I believe you missed the where clause. This is an equijoin.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Don't believe I did. It is only an "equjoin" because neither set had the ID duplicated.&lt;/P&gt;
&lt;PRE&gt;Data One;
   input ID x $;
datalines;
1  a
1  b
2  b
;

data two;
  input ID y $;
datalines;
1   A
1  B
1  C
3  C
;

proc sql;  create table want as
  select *
  from One, Two  where One.ID = Two.ID;
quit;&lt;/PRE&gt;
&lt;P&gt;Yields 6 rows of output. Which is why I asked for clarification as to what was actually intended for the output when ID values are duplicated.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Dec 2023 15:34:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-select-everything-with-2-tables-that-have-1-common-ID/m-p/906721#M40513</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-12-07T15:34:53Z</dc:date>
    </item>
    <item>
      <title>Re: How do I select everything with 2 tables that have 1 common ID using PROC SQL?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-select-everything-with-2-tables-that-have-1-common-ID/m-p/906881#M40540</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp; From the SAS docu&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/v_045/fedsqlref/p1q7agzgxs9ik5n1p7k3sdft0u9u.htm#:~:text=An%20equijoin%20is%20a%20simple,by%20using%20the%20AND%20operator." target="_self"&gt;Join Operations&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1701986884488.png" style="width: 694px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/90996i31818522550788B5/image-dimensions/694x58?v=v2" width="694" height="58" role="button" title="Patrick_0-1701986884488.png" alt="Patrick_0-1701986884488.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Dec 2023 22:09:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-select-everything-with-2-tables-that-have-1-common-ID/m-p/906881#M40540</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-12-07T22:09:23Z</dc:date>
    </item>
  </channel>
</rss>

