<?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: Combining two data sets with SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Combining-two-data-sets-with-SQL/m-p/751340#M236505</link>
    <description>&lt;P&gt;SQL uses datasetidenfier.variablename syntax. When you use a LIBRARY as part of the name you asking for something that SQL doesn't expect to see. So you use an ALIAS to refer to the libname.dataset name&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;Proc Sql noprint;
CREATE TABLE SASCDC_2.Contact_ID_Employment_NAICS AS
   Select * 
   From SASCDC_2.Set_Contact_Person_Employment AS A
   Left Join SASCDC_2.Set_Contact_ID_Employment AS B
   On A.Place_of_Employment = B.Place_of_Employment;
quit;&lt;/LI-CODE&gt;
&lt;P&gt;The "as" after the data set name is optional but I tend to use it as a reminder that A is referencing&amp;nbsp; that set more clearly.&lt;/P&gt;
&lt;P&gt;You would also likely want : Select A.*, B.* to get variables from both sets though there will be a message about one of the variables "already on the data set" because the variable(s) joined on come from both sets. Or use explicit lists of the variables using A. and B. prefixes.&lt;/P&gt;</description>
    <pubDate>Wed, 30 Jun 2021 18:51:44 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-06-30T18:51:44Z</dc:date>
    <item>
      <title>Combining two data sets with SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-two-data-sets-with-SQL/m-p/751322#M236496</link>
      <description>&lt;P&gt;I have a straightforward ask.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have two datasets&amp;nbsp; DS1 and DS2.&amp;nbsp; DS1&amp;nbsp; has two columns: Contact_ID ,&amp;nbsp; Place_of_employment&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DS2&amp;nbsp; several fields:&amp;nbsp; Place_of_employment&amp;nbsp; ,&amp;nbsp;&amp;nbsp; NAICS_code &amp;nbsp; and several others ..........&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My question is that I want to join the datasets using&amp;nbsp; SQL&amp;nbsp;&amp;nbsp;&amp;nbsp; DS1 --&amp;gt; DS2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;so the combined dataset&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DS_ALL&amp;nbsp; has as columns:&amp;nbsp; Contact_ID,&amp;nbsp;&amp;nbsp; Place of Employment,&amp;nbsp; NAICS_Code,&amp;nbsp; other columns .....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have included my code where I was using a Left Join&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc Sql noprint;
CREATE TABLE SASCDC_2.Contact_ID_Employment_NAICS AS
   Select * 
   From SASCDC_2.Set_Contact_Person_Employment
   Left Join SASCDC_2.Set_Contact_ID_Employment
   On SASCDC_2.Set_Contact_Person_Employment.Place_of_Employment = SASCDC_2.Set_Contact_ID_Employment.Place_of_Employment;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But the code is not correct as can be seen by Log&lt;/P&gt;
&lt;PRE&gt;Select *
85      From SASCDC_2.Set_Contact_Person_Employment
86      Left Join SASCDC_2.Set_Contact_ID_Employment
87      On SASCDC_2.Set_Contact_Person_Employment.Place_of_Employment =
                                                 -
                                                 22
                                                 76
87 ! SASCDC_2.Set_Contact_ID_Employment.Place_of_Employment;
ERROR 22-322: Syntax error, expecting one of the following: ;, !, !!, &amp;amp;, *, **, +, ',', -, /,
              &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, ?, AND, ANSIMISS, BETWEEN, CONTAINS, CROSS, EQ, EQT,
              EXCEPT, FULL, GE, GET, GROUP, GT, GTT, HAVING, IN, INNER, INTERSECT, IS, JOIN,
              LE, LEFT, LET, LIKE, LT, LTT, NATURAL, NE, NET, NOMISS, NOT, NOTIN, OR, ORDER,
              OUTER, RIGHT, UNION, WHERE, ^, ^=, |, ||, ~, ~=.

&lt;/PRE&gt;
&lt;P&gt;Appreciate your help in this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;wklierman&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jun 2021 18:08:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-two-data-sets-with-SQL/m-p/751322#M236496</guid>
      <dc:creator>wlierman</dc:creator>
      <dc:date>2021-06-30T18:08:55Z</dc:date>
    </item>
    <item>
      <title>Re: Combining two data sets with SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-two-data-sets-with-SQL/m-p/751340#M236505</link>
      <description>&lt;P&gt;SQL uses datasetidenfier.variablename syntax. When you use a LIBRARY as part of the name you asking for something that SQL doesn't expect to see. So you use an ALIAS to refer to the libname.dataset name&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;Proc Sql noprint;
CREATE TABLE SASCDC_2.Contact_ID_Employment_NAICS AS
   Select * 
   From SASCDC_2.Set_Contact_Person_Employment AS A
   Left Join SASCDC_2.Set_Contact_ID_Employment AS B
   On A.Place_of_Employment = B.Place_of_Employment;
quit;&lt;/LI-CODE&gt;
&lt;P&gt;The "as" after the data set name is optional but I tend to use it as a reminder that A is referencing&amp;nbsp; that set more clearly.&lt;/P&gt;
&lt;P&gt;You would also likely want : Select A.*, B.* to get variables from both sets though there will be a message about one of the variables "already on the data set" because the variable(s) joined on come from both sets. Or use explicit lists of the variables using A. and B. prefixes.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jun 2021 18:51:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-two-data-sets-with-SQL/m-p/751340#M236505</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-06-30T18:51:44Z</dc:date>
    </item>
    <item>
      <title>Re: Combining two data sets with SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combining-two-data-sets-with-SQL/m-p/751363#M236517</link>
      <description>&lt;P&gt;Thank you for the quick response. I tried a regular data step sorting by place_of_employment&lt;/P&gt;
&lt;P&gt;that messed things up because values for the other variables did not come through.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for this approach.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;wklierman&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jun 2021 20:36:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combining-two-data-sets-with-SQL/m-p/751363#M236517</guid>
      <dc:creator>wlierman</dc:creator>
      <dc:date>2021-06-30T20:36:08Z</dc:date>
    </item>
  </channel>
</rss>

