<?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 - inner join and left join in one step in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-inner-join-and-left-join-in-one-step/m-p/125767#M34591</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;proc sql; create table res as ( select x.id,x.breakfast,c.category from (select a.id,&amp;nbsp; b.breakfast from a join b on a.id=b.id) x left join c on x.breakfast=c.breakfast ); run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 15 Jan 2013 16:06:59 GMT</pubDate>
    <dc:creator>NagendraKumarK</dc:creator>
    <dc:date>2013-01-15T16:06:59Z</dc:date>
    <item>
      <title>Proc SQL - inner join and left join in one step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-inner-join-and-left-join-in-one-step/m-p/125764#M34588</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can I have inner join and left join in one step in PROC SQL, or I've to do in 2 steps or do with subquery? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is an example. &lt;/P&gt;&lt;P&gt;1. I want ID in both tables A and B (so just ID=1 and 2), so it's inner join (in data step it's in A and B)&lt;/P&gt;&lt;P&gt;2. I then want to link the cases to table C to get their breakfast category. Since it's likely the category in C is not complete, I'd need to use left join to keep records (i.e. mushrrom) from step 1 (in data step it's in A).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data a; input id x1;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1 11&lt;/P&gt;&lt;P&gt;2 22 &lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;data b; input id x2 breakfast $;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1 1 apple&lt;/P&gt;&lt;P&gt;2 1 carrot&lt;/P&gt;&lt;P&gt;2 1 mushroom&lt;/P&gt;&lt;P&gt;3 1 pepper&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;data c; input breakfast $ category $; &lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;apple&amp;nbsp; fruit&lt;/P&gt;&lt;P&gt;orange fruit&lt;/P&gt;&lt;P&gt;carrot&amp;nbsp; vegetable&lt;/P&gt;&lt;P&gt;pepper vegetable&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data wanted:&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; breakfast&amp;nbsp;&amp;nbsp;&amp;nbsp; category&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp; apple&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fruit&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; carrot&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; vegetable&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; mushroom&amp;nbsp;&amp;nbsp;&amp;nbsp; .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SAS code in 2 steps:&lt;/P&gt;&lt;P&gt;proc sql; create table d as &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select&amp;nbsp; a.id, b.breakfast&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from a as a, b as b&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; where a.id=b.id;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select&amp;nbsp; d.id, d.breakfast, c.category&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from d as d left join c as c&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; on d.breakfast=c.breakfast;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;proc print data=want noobs; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A related question is can I do inner join (in A and B) and in A but not C in one step? I read that EXCEPT can do the job, but when I copied the example code, it didn't seem right. For the fruit example above, the data set should look like&lt;/P&gt;&lt;P&gt;&amp;nbsp; ID&amp;nbsp; breakfast&amp;nbsp;&amp;nbsp;&amp;nbsp; category&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp; mushroom&amp;nbsp; .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks in advance.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Jan 2013 07:24:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-inner-join-and-left-join-in-one-step/m-p/125764#M34588</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2013-01-15T07:24:49Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - inner join and left join in one step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-inner-join-and-left-join-in-one-step/m-p/125765#M34589</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It seems that you confuse left join with except logic, which do you want?&lt;/P&gt;&lt;P&gt;And yes, you can nestle joins in the same SQL step, but I recommend that you you explicit join syntax (i.e. a inner join b on...) to avoid unexpected results.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Jan 2013 07:38:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-inner-join-and-left-join-in-one-step/m-p/125765#M34589</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2013-01-15T07:38:24Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - inner join and left join in one step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-inner-join-and-left-join-in-one-step/m-p/125766#M34590</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Would the following piece of code do what you are expecting ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table d as &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select&amp;nbsp; a.id&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b.breakfast&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; c.category&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from a&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; inner join b&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on a.id = b.id&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; left join c&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on b.breakfast = c.breakfast;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data e;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set d (where=(missing(category)));&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Florent&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Jan 2013 12:59:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-inner-join-and-left-join-in-one-step/m-p/125766#M34590</guid>
      <dc:creator>Florent</dc:creator>
      <dc:date>2013-01-15T12:59:43Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - inner join and left join in one step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-inner-join-and-left-join-in-one-step/m-p/125767#M34591</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;proc sql; create table res as ( select x.id,x.breakfast,c.category from (select a.id,&amp;nbsp; b.breakfast from a join b on a.id=b.id) x left join c on x.breakfast=c.breakfast ); run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Jan 2013 16:06:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-inner-join-and-left-join-in-one-step/m-p/125767#M34591</guid>
      <dc:creator>NagendraKumarK</dc:creator>
      <dc:date>2013-01-15T16:06:59Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - inner join and left join in one step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-inner-join-and-left-join-in-one-step/m-p/125768#M34592</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks NagendraKumarK for the subquery code. And thanks especially Florent for the code, which is exactly what I want, for my first question.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just a question though, if it possible to do If A and B on ID, and If A but not C on breakfast in one code? I see Florent's code in two steps. Possibly in one step.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LinusH, sorry my questions weren't phrased clearly. It's two part questions. First how do I do inner join and left join in one code (I've never seen sample code as Florent's, so it really helped). Second, how do I do inner join (If A and B) and If A but not C in one code. Florent's two-step code is great. But I'm wondering it it can be done in one step.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Jan 2013 18:29:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-inner-join-and-left-join-in-one-step/m-p/125768#M34592</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2013-01-15T18:29:08Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - inner join and left join in one step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-inner-join-and-left-join-in-one-step/m-p/125769#M34593</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The first step (table d) contains everything which is in A and B, and potentially in C. When there is no match with the table C then the content of the category field will be empty.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want to have table e created at the same time as table d (so in one step), then you should use make a dastep using the merge statement and play with the inA, inB, inC variable you can create at that time. The disadvantage of making a datastep instead of a proc sql is that it requires you firstly sort tables a, b and c in the same order... so in the end you would have 3 sort statements + 1 datastep. There is no way to create two datasets at a time with a "create table" statement of the proc sql.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope it answers to your questions.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Jan 2013 22:47:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-inner-join-and-left-join-in-one-step/m-p/125769#M34593</guid>
      <dc:creator>Florent</dc:creator>
      <dc:date>2013-01-15T22:47:15Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - inner join and left join in one step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-inner-join-and-left-join-in-one-step/m-p/125770#M34594</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Second question, just combine an inner join with a sub-query (not in() ).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Jan 2013 11:40:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-inner-join-and-left-join-in-one-step/m-p/125770#M34594</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2013-01-16T11:40:01Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - inner join and left join in one step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-inner-join-and-left-join-in-one-step/m-p/125771#M34595</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the replies. I've a related question still about doing various merges, hoping to find NO NEED to do sub-queries. The example above is a simpler one as it is always using A to inner join with B, and to left join with C. But the example below doesn't always start with A. I get the feeling that sub-queres are the only way to go in SQL, or use data step. Just want to confirm.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data a; input patient_id hospital_id los;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1 100 1&lt;/P&gt;&lt;P&gt;1 102 2&lt;/P&gt;&lt;P&gt;2 100 4&lt;/P&gt;&lt;P&gt;3 101 5&lt;/P&gt;&lt;P&gt;3 103 10&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;data b; input patient_id hospital_id wtcases;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1 100 1.5&lt;/P&gt;&lt;P&gt;1 102 2.2&lt;/P&gt;&lt;P&gt;2 100 1.1&lt;/P&gt;&lt;P&gt;3 103 4.1&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;data c; input hospital_id postcode $;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;100 58823&lt;/P&gt;&lt;P&gt;101 45000&lt;/P&gt;&lt;P&gt;102 45001&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;data d; input postcode $ area;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;58823&amp;nbsp; 51&lt;/P&gt;&lt;P&gt;45000&amp;nbsp; 52&lt;/P&gt;&lt;P&gt;99999&amp;nbsp; 99&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*The code below actualy wouldn't run uless I take out what's after SELECT, and use just SELECT *. Then I see it's outputting all combinations and realized the FROM statement isn't doing what I thought SQL could do.&lt;/P&gt;&lt;P&gt;Proc sql; create table want as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select a.id, a.los, b.hospital_id, b.wtcases, c.postcode, d.area&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from a inner join b on a.patient_id=b.patient_id and a.hospital_id=b.hospital_id,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b left join c on b.hospital_id=c.hospital_id,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; c left join d on c.postcode=d.postcode;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;proc print data=a noobs; run;&lt;/P&gt;&lt;P&gt;proc print data=b noobs; run;&lt;/P&gt;&lt;P&gt;proc print data=c noobs; run;&lt;/P&gt;&lt;P&gt;proc print data=d noobs; run;&lt;/P&gt;&lt;P&gt;proc print data=want; run;.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Jan 2013 19:59:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-inner-join-and-left-join-in-one-step/m-p/125771#M34595</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2013-01-16T19:59:20Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - inner join and left join in one step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-inner-join-and-left-join-in-one-step/m-p/125772#M34596</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When using the "inner join"/"left join"/"right join" syntax, you cannot put a comma after the join condition(s). Furthermore, you don't have to repeat the table names which have already been used in a join. With your code, it gives: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Proc sql;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table want as&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select a.id, a.los, b.hospital_id, b.wtcases, c.postcode, d.area&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from a&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; inner join b&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on a.patient_id = b.patient_id&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and a.hospital_id = b.hospital_id&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; left join c&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on b.hospital_id = c.hospital_id&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; left join d&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on c.postcode=d.postcode;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;quit;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;proc print data=a noobs; run;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;proc print data=b noobs; run;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;proc print data=c noobs; run;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;proc print data=d noobs; run;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;proc print data=want; run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Jan 2013 21:39:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-inner-join-and-left-join-in-one-step/m-p/125772#M34596</guid>
      <dc:creator>Florent</dc:creator>
      <dc:date>2013-01-16T21:39:23Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - inner join and left join in one step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-inner-join-and-left-join-in-one-step/m-p/125773#M34597</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks a million. SQL is indeed very powerful. The code worked for a large part. What it didn't work is the following. If you have answers for it, let me know. Otherwise I'll change to answered.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. I need to change from &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT a.id, a.los, b.hospital_id, b.wtcases, c.postcode, d.area&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; to&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT *&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; otherwise it's giving an error message "ERROR: Column id could not be found in the table/view identified with the correlation name A" even though there is nothing wrong.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. It's outputting the following cases, I thought inner join A and B by patient ID and Hospital ID would get rid of patient ID=3&amp;nbsp; all together. But it got rid of the one from hospital 101 and kept the one from hospital 103. &lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 384px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl65" height="40" width="64"&gt;patient_id&lt;/TD&gt;&lt;TD class="xl66" width="64"&gt;hospital_id&lt;/TD&gt;&lt;TD class="xl66" width="64"&gt;los&lt;/TD&gt;&lt;TD class="xl66" width="64"&gt;wtcases&lt;/TD&gt;&lt;TD class="xl66" width="64"&gt;postcode&lt;/TD&gt;&lt;TD class="xl66" width="64"&gt;area&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl67" height="20" width="64"&gt;3&lt;/TD&gt;&lt;TD class="xl68" width="64"&gt;103&lt;/TD&gt;&lt;TD class="xl68" width="64"&gt;10&lt;/TD&gt;&lt;TD class="xl68" width="64"&gt;4.1&lt;/TD&gt;&lt;TD class="xl68" width="64"&gt;&lt;/TD&gt;&lt;TD class="xl68" width="64"&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl67" height="20" width="64"&gt;1&lt;/TD&gt;&lt;TD class="xl68" width="64"&gt;102&lt;/TD&gt;&lt;TD class="xl68" width="64"&gt;2&lt;/TD&gt;&lt;TD class="xl68" width="64"&gt;2.2&lt;/TD&gt;&lt;TD class="xl68" width="64"&gt;45001&lt;/TD&gt;&lt;TD class="xl68" width="64"&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl67" height="20" width="64"&gt;2&lt;/TD&gt;&lt;TD class="xl68" width="64"&gt;100&lt;/TD&gt;&lt;TD class="xl68" width="64"&gt;4&lt;/TD&gt;&lt;TD class="xl68" width="64"&gt;1.1&lt;/TD&gt;&lt;TD class="xl68" width="64"&gt;58823&lt;/TD&gt;&lt;TD class="xl68" width="64"&gt;51&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl67" height="20" width="64"&gt;1&lt;/TD&gt;&lt;TD class="xl68" width="64"&gt;100&lt;/TD&gt;&lt;TD class="xl68" width="64"&gt;1&lt;/TD&gt;&lt;TD class="xl68" width="64"&gt;1.5&lt;/TD&gt;&lt;TD class="xl68" width="64"&gt;58823&lt;/TD&gt;&lt;TD class="xl68" width="64"&gt;51&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl67" height="20" width="64"&gt;&lt;/TD&gt;&lt;TD class="xl68" width="64"&gt;&lt;/TD&gt;&lt;TD class="xl68" width="64"&gt;&lt;/TD&gt;&lt;TD class="xl68" width="64"&gt;&lt;/TD&gt;&lt;TD class="xl68" width="64"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Anyway thanks very much for the reply. I didn't know I could use SQL this way. Let me know if there are answers to the above questions. Otherwise I'll close this discussion.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jan 2013 02:19:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-inner-join-and-left-join-in-one-step/m-p/125773#M34597</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2013-01-18T02:19:57Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - inner join and left join in one step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-inner-join-and-left-join-in-one-step/m-p/125774#M34598</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Concerning the first point, it is clear that the "ID" is not available in table A. It should be replaced by "patient_id".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For the second bullet point, I do not agree with the fact that the line concerning hospital 103 and patient 3 should be excluded from the table. If you look at tables A and B, you will find this patient-hospital combination in both of them. Thus this is logical to find it back in your final table when using inner joins.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope it helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jan 2013 12:51:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-inner-join-and-left-join-in-one-step/m-p/125774#M34598</guid>
      <dc:creator>Florent</dc:creator>
      <dc:date>2013-01-18T12:51:09Z</dc:date>
    </item>
  </channel>
</rss>

