<?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 PROC SQL FULL OUTER JOIN naming syntax confusion in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-FULL-OUTER-JOIN-naming-syntax-confusion/m-p/547534#M8391</link>
    <description>&lt;P&gt;I'm writing a PROC SQL code to full outer join 2 tables. I am somewhat familiar with the syntax in PostgreSQL but am unsure what the naming syntax is when writing a step like this inside PROC SQL. My issue is I get a syntax error on the last line before the run statement at the period between the first diagnosis and DX_KEY. In SAS how is one supposed to identify the primary key matching columns? The chop is the name of the library I created.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ON chop.diagnosis.DX_KEY = chop.visit_diagnosis.DX_KEY;&lt;BR /&gt;-&lt;BR /&gt;22&lt;BR /&gt;76&lt;BR /&gt;ERROR 22-322: Syntax error,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE chop_dx_joined&lt;BR /&gt;AS Select * FROM chop.diagnosis&lt;BR /&gt;FULL JOIN chop.visit_diagnosis&lt;BR /&gt;ON chop.diagnosis.DX_KEY = chop.visit_diagnosis.DX_KEY;&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Mon, 01 Apr 2019 02:40:21 GMT</pubDate>
    <dc:creator>moseland</dc:creator>
    <dc:date>2019-04-01T02:40:21Z</dc:date>
    <item>
      <title>PROC SQL FULL OUTER JOIN naming syntax confusion</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-FULL-OUTER-JOIN-naming-syntax-confusion/m-p/547534#M8391</link>
      <description>&lt;P&gt;I'm writing a PROC SQL code to full outer join 2 tables. I am somewhat familiar with the syntax in PostgreSQL but am unsure what the naming syntax is when writing a step like this inside PROC SQL. My issue is I get a syntax error on the last line before the run statement at the period between the first diagnosis and DX_KEY. In SAS how is one supposed to identify the primary key matching columns? The chop is the name of the library I created.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ON chop.diagnosis.DX_KEY = chop.visit_diagnosis.DX_KEY;&lt;BR /&gt;-&lt;BR /&gt;22&lt;BR /&gt;76&lt;BR /&gt;ERROR 22-322: Syntax error,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE chop_dx_joined&lt;BR /&gt;AS Select * FROM chop.diagnosis&lt;BR /&gt;FULL JOIN chop.visit_diagnosis&lt;BR /&gt;ON chop.diagnosis.DX_KEY = chop.visit_diagnosis.DX_KEY;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Apr 2019 02:40:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-FULL-OUTER-JOIN-naming-syntax-confusion/m-p/547534#M8391</guid>
      <dc:creator>moseland</dc:creator>
      <dc:date>2019-04-01T02:40:21Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL FULL OUTER JOIN naming syntax confusion</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-FULL-OUTER-JOIN-naming-syntax-confusion/m-p/547539#M8392</link>
      <description>&lt;P&gt;You have the syntax correct, but are confused about how to use ALIASes in SQL code to clarify which specific variable you are referencing.&lt;/P&gt;
&lt;P&gt;The ALIAS is a ONE word string that refers to a table mentioned in your SQL statement. By default the alias will be the member name of the dataset you are referencing.&amp;nbsp; If you want to use a different alias then add the alias after the table (dataset) name in your statement. This is critical when you are using either the same dataset twice or two datasets with the same member name from two different libraries.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this example I have used LEFT and RIGHT as the aliases.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table chop_dx_joined as
  select *
  from chop.diagnosis LEFT
  full join chop.visit_diagnosis RIGHT
  on LEFT.dx_key = RIGHT.dx_key
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note this is standard SQL syntax. So it will work just as well in PosgreSQL's implementation of SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Apr 2019 03:00:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-FULL-OUTER-JOIN-naming-syntax-confusion/m-p/547539#M8392</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-04-01T03:00:31Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL FULL OUTER JOIN naming syntax confusion</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-FULL-OUTER-JOIN-naming-syntax-confusion/m-p/547540#M8393</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/222221"&gt;@moseland&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can't use 3 level name syntax like "&lt;SPAN&gt;chop&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;diagnosis&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;DX_KEY&lt;/SPAN&gt;" with SAS SQL. Use aliases instead.&lt;/P&gt;
&lt;P&gt;For the select clause: If you have same named variables in both source tables then you need to explicitly define which one to use. A simple select * won't do.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
  CREATE TABLE chop_dx_joined AS
    Select t1.* 
      FROM chop.diagnosis t1 FULL JOIN chop.visit_diagnosis t2
        ON t1.DX_KEY = t2.DX_KEY;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Apr 2019 03:07:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-FULL-OUTER-JOIN-naming-syntax-confusion/m-p/547540#M8393</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-04-01T03:07:56Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL FULL OUTER JOIN naming syntax confusion</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-FULL-OUTER-JOIN-naming-syntax-confusion/m-p/547787#M8436</link>
      <description>&lt;P&gt;Thank you! The code was successful. A follow up question: For organization, could I declare the aliases at the beginning of the PROC SQL step? For example,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;create table chop_dx_joined&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #333333; cursor: text; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;diagnosis AS T1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;visit_diagnosis AS T2&lt;BR /&gt;select *&lt;BR /&gt;from chop.diagnosis&lt;BR /&gt;full join chop.visit_diagnosis&lt;BR /&gt;on T1.dx_key = T2.dx_key;&lt;BR /&gt;run;&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>Tue, 02 Apr 2019 02:07:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-FULL-OUTER-JOIN-naming-syntax-confusion/m-p/547787#M8436</guid>
      <dc:creator>moseland</dc:creator>
      <dc:date>2019-04-02T02:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL FULL OUTER JOIN naming syntax confusion</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-FULL-OUTER-JOIN-naming-syntax-confusion/m-p/547788#M8437</link>
      <description>&lt;P&gt;Thank you! This explanation is extremely helpful.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2019 02:08:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-FULL-OUTER-JOIN-naming-syntax-confusion/m-p/547788#M8437</guid>
      <dc:creator>moseland</dc:creator>
      <dc:date>2019-04-02T02:08:47Z</dc:date>
    </item>
  </channel>
</rss>

