<?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: Combine Data Using SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Combine-Data-Using-SQL/m-p/599352#M173004</link>
    <description>&lt;P&gt;When SAS sees something like this in Proc SQL&lt;/P&gt;
&lt;PRE&gt;on rank2018.NOC=rank2016.NOC&lt;/PRE&gt;
&lt;P&gt;It expects Rank2018 and Rank2016 to be a single reference to a data set. But your datasets are in your library AB but the ON clause does not know that. So you&amp;nbsp;provide an ALIAS n the From clause &amp;nbsp;to have a single reference such as:&lt;/P&gt;
&lt;PRE&gt;from ab.rank2018 as rank2018 inner join ab.rank2016 as rank2016
&lt;/PRE&gt;
&lt;P&gt;so references such as rank2018.NOC can get back to the actual data source for the NOC.&lt;/P&gt;
&lt;P&gt;The AS is optional in assigning the alias but I think it helps readability.&lt;/P&gt;
&lt;P&gt;Most people tend to use something shorter for the alias like T1 (for table 1) or A to avoid any extra typing when referencing the variables. You can see that typing A.Noc is quicker than Rank2018.Noc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To reference two variables with the same names in the source the data sets you would use AS to rename one or both:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Select a.noc, b.noc as NOC2016&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for example would have an output variable named NOC that came from the aliased set A and another named NOC2016 that was the value of the aliased set B Noc variable. (Yet another reason for short aliases)&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>Fri, 25 Oct 2019 14:59:54 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-10-25T14:59:54Z</dc:date>
    <item>
      <title>Combine Data Using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-Data-Using-SQL/m-p/599210#M172916</link>
      <description>&lt;P&gt;Hi, I'm trying to use SQL to inner join 2 SAS files, here is what I have:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	select Rank.NOC, Rank.Country, Gold_2018, Silver_2018, Bronze_2018
	from ab.rank2018 inner join ab.rank2016
	on rank2018.NOC=rank2016.NOC
	on rank2018.Country=rank2016.Country;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;My question is that because Country and NOC occur in both tables, I have the use the table prefix to indicate which column to use, which I choose olympics2016, however it doesn't work, it still gives me two table. Can someone please help me to fix it? Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2019 01:58:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-Data-Using-SQL/m-p/599210#M172916</guid>
      <dc:creator>aabbccwyt</dc:creator>
      <dc:date>2019-10-25T01:58:00Z</dc:date>
    </item>
    <item>
      <title>Re: Combine Data Using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-Data-Using-SQL/m-p/599211#M172917</link>
      <description>&lt;P&gt;Your join criteria doesn't look right. The second ON should be AND.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	select Rank.NOC, Rank.Country, Gold_2018, Silver_2018, Bronze_2018
	from ab.rank2018 inner join ab.rank2016
	on rank2018.NOC=rank2016.NOC
	and rank2018.Country=rank2016.Country;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Oct 2019 02:05:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-Data-Using-SQL/m-p/599211#M172917</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-10-25T02:05:24Z</dc:date>
    </item>
    <item>
      <title>Re: Combine Data Using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-Data-Using-SQL/m-p/599215#M172920</link>
      <description>&lt;P&gt;Now it says:&amp;nbsp;&lt;SPAN&gt;Unresolved reference to table/correlation name Rank.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I know it has to do something with the second ON but I'm not sure what is it.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2019 02:34:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-Data-Using-SQL/m-p/599215#M172920</guid>
      <dc:creator>aabbccwyt</dc:creator>
      <dc:date>2019-10-25T02:34:48Z</dc:date>
    </item>
    <item>
      <title>Re: Combine Data Using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-Data-Using-SQL/m-p/599216#M172921</link>
      <description>&lt;P&gt;When you use RANK.tablename, I suppose RANK is a defined library?&lt;/P&gt;
&lt;P&gt;Also, where comes the 2018 and 2016 in the name of the library RANK?&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2019 02:37:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-Data-Using-SQL/m-p/599216#M172921</guid>
      <dc:creator>jpprovost</dc:creator>
      <dc:date>2019-10-25T02:37:12Z</dc:date>
    </item>
    <item>
      <title>Re: Combine Data Using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-Data-Using-SQL/m-p/599218#M172922</link>
      <description>&lt;P&gt;They are sas7bdat files, here are my previous code if needed&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=ab.rank2016;
proc print data=ab.rank2018;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;ab is basically the path.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2019 02:43:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-Data-Using-SQL/m-p/599218#M172922</guid>
      <dc:creator>aabbccwyt</dc:creator>
      <dc:date>2019-10-25T02:43:49Z</dc:date>
    </item>
    <item>
      <title>Re: Combine Data Using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-Data-Using-SQL/m-p/599219#M172923</link>
      <description>&lt;P&gt;Maybe the "ab" part is missing ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select  Rank.NOC, 
           Rank.Country, 
           Gold_2018, 
           Silver_2018, 
           Bronze_2018
	
from ab.rank2018 

inner join ab.rank2016 on 
   ab.rank2018.NOC=rank2016.NOC   and 
   ab.rank2018.Country=rank2016.Country;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, does the rank2016.xxxx have also the "ab" part in their part?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2019 02:48:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-Data-Using-SQL/m-p/599219#M172923</guid>
      <dc:creator>jpprovost</dc:creator>
      <dc:date>2019-10-25T02:48:28Z</dc:date>
    </item>
    <item>
      <title>Re: Combine Data Using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-Data-Using-SQL/m-p/599223#M172924</link>
      <description>&lt;P&gt;Proper syntax would look like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	select 
		a.NOC, 
		a.Country, 
		b.Gold_2018, 
		b.Silver_2018, 
		b.Bronze_2018
	from 
		ab.rank2016 as a inner join 
		ab.rank2018 as b 
		on a.NOC=b.NOC and a.Country=b.Country;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Oct 2019 02:58:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-Data-Using-SQL/m-p/599223#M172924</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-10-25T02:58:02Z</dc:date>
    </item>
    <item>
      <title>Re: Combine Data Using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-Data-Using-SQL/m-p/599352#M173004</link>
      <description>&lt;P&gt;When SAS sees something like this in Proc SQL&lt;/P&gt;
&lt;PRE&gt;on rank2018.NOC=rank2016.NOC&lt;/PRE&gt;
&lt;P&gt;It expects Rank2018 and Rank2016 to be a single reference to a data set. But your datasets are in your library AB but the ON clause does not know that. So you&amp;nbsp;provide an ALIAS n the From clause &amp;nbsp;to have a single reference such as:&lt;/P&gt;
&lt;PRE&gt;from ab.rank2018 as rank2018 inner join ab.rank2016 as rank2016
&lt;/PRE&gt;
&lt;P&gt;so references such as rank2018.NOC can get back to the actual data source for the NOC.&lt;/P&gt;
&lt;P&gt;The AS is optional in assigning the alias but I think it helps readability.&lt;/P&gt;
&lt;P&gt;Most people tend to use something shorter for the alias like T1 (for table 1) or A to avoid any extra typing when referencing the variables. You can see that typing A.Noc is quicker than Rank2018.Noc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To reference two variables with the same names in the source the data sets you would use AS to rename one or both:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Select a.noc, b.noc as NOC2016&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for example would have an output variable named NOC that came from the aliased set A and another named NOC2016 that was the value of the aliased set B Noc variable. (Yet another reason for short aliases)&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>Fri, 25 Oct 2019 14:59:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-Data-Using-SQL/m-p/599352#M173004</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-10-25T14:59:54Z</dc:date>
    </item>
  </channel>
</rss>

