<?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: Joining two tables on two variables in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Joining-two-tables-on-two-variables/m-p/513778#M73169</link>
    <description>&lt;P&gt;If this were a DATA step instead of SQL, the answer would be very clear.&amp;nbsp; Since it's SQL, however, you will have to check whether this is correct or not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A stand-alone WHERE clause applies to both sources of data.&amp;nbsp; Both CONDITION and VISIT would need to contain CONDITION_ID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it turns out that SQL follows the same rules, (and if CONDITION_ID appears in only one of the incoming data sets), you could get around the issue by using two CREATE statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CREATE statement #1:&amp;nbsp; Create a view that subsets the records from one of the sources.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CREATE statement #2:&amp;nbsp; Join that view with the other source.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course, if this is not the issue, it would be helpful for you to provide some details ... what doesn't work?&amp;nbsp; Why is the result not what you want?&amp;nbsp; The SAS log would help.&lt;/P&gt;</description>
    <pubDate>Fri, 16 Nov 2018 04:30:05 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2018-11-16T04:30:05Z</dc:date>
    <item>
      <title>Joining two tables on two variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Joining-two-tables-on-two-variables/m-p/513773#M73167</link>
      <description>&lt;P&gt;&lt;FONT face="times new roman,times" size="4"&gt;Hi SAS users,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="times new roman,times" size="4"&gt;I would like to join 2 tables on 2 variables limiting only the records from condition_concept table.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="times new roman,times" size="4"&gt;But the below code doesn't work.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="times new roman,times" size="4"&gt;Would you be able to point me out why?&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="times new roman,times" size="4"&gt;Thank you.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;CREATE TABLE criteria AS
	SELECT a.*, a.year AS condition_year, b.year AS visit_year 
	FROM condition a INNER JOIN visit b
	ON a.id=b.id AND a.visit_id=b.visit_id
	WHERE condition_id IN 
	(SELECT DISTINCT(target_id) FROM condition_concept)
	ORDER BY a.id&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Nov 2018 03:39:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Joining-two-tables-on-two-variables/m-p/513773#M73167</guid>
      <dc:creator>Miracle</dc:creator>
      <dc:date>2018-11-16T03:39:22Z</dc:date>
    </item>
    <item>
      <title>Re: Joining two tables on two variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Joining-two-tables-on-two-variables/m-p/513776#M73168</link>
      <description>&lt;P&gt;does your condition have a table that it is coming from is it table a or table b?&lt;/P&gt;</description>
      <pubDate>Fri, 16 Nov 2018 04:16:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Joining-two-tables-on-two-variables/m-p/513776#M73168</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2018-11-16T04:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: Joining two tables on two variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Joining-two-tables-on-two-variables/m-p/513778#M73169</link>
      <description>&lt;P&gt;If this were a DATA step instead of SQL, the answer would be very clear.&amp;nbsp; Since it's SQL, however, you will have to check whether this is correct or not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A stand-alone WHERE clause applies to both sources of data.&amp;nbsp; Both CONDITION and VISIT would need to contain CONDITION_ID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it turns out that SQL follows the same rules, (and if CONDITION_ID appears in only one of the incoming data sets), you could get around the issue by using two CREATE statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CREATE statement #1:&amp;nbsp; Create a view that subsets the records from one of the sources.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CREATE statement #2:&amp;nbsp; Join that view with the other source.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course, if this is not the issue, it would be helpful for you to provide some details ... what doesn't work?&amp;nbsp; Why is the result not what you want?&amp;nbsp; The SAS log would help.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Nov 2018 04:30:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Joining-two-tables-on-two-variables/m-p/513778#M73169</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-11-16T04:30:05Z</dc:date>
    </item>
    <item>
      <title>Re: Joining two tables on two variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Joining-two-tables-on-two-variables/m-p/513988#M73185</link>
      <description>&lt;P&gt;Doesn't work is awful vague.&lt;BR /&gt;&lt;BR /&gt;Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.&lt;BR /&gt;&lt;BR /&gt;No output? Post any log in a code box.&lt;BR /&gt;&lt;BR /&gt;Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat&lt;/A&gt;... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And you are using &lt;STRONG&gt;three&lt;/STRONG&gt; tables. Perhaps you need to JOIN with the third table instead?&lt;/P&gt;</description>
      <pubDate>Fri, 16 Nov 2018 17:17:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Joining-two-tables-on-two-variables/m-p/513988#M73185</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-11-16T17:17:51Z</dc:date>
    </item>
  </channel>
</rss>

