<?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 Errors are different based on the order of the tables that I am joining in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Errors-are-different-based-on-the-order-of-the-tables/m-p/866662#M342273</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm having problems with this piece of code. I get different errors when I change the order of the tables I'm left joining.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;
CONNECT TO SQLSVR AS CDW(DATAsrc=&amp;lt;project name&amp;gt; &amp;amp;SQL_OPTIMAL.);

create table scr0 as select scrssn, 
	labchemresultnumericvalue as num, 
	labchemcompletedatetime as res, 
	upper(LabChemTestName) as test_name, 
	upper(c.topography) as topography, e.loinc, 35 as dsslarno
	
 connection to cdw

(select d.scrssn, a.patientsid, labchemresultnumericvalue
as num, labchemcompletedatetime as res, 
upper(LabChemTestName) as test_name, 
upper(c.topography) as topography, e.loinc from

src.chem_labchem as a

	left join CDWWork.dim.labchemtest as  b on  
		a.LabChemTestSID=b.labchemtestsid

	left join CDWWork.dim.Topography as c  on 
		a.TopographySID=c.TopographySID) 

	left join Src.CohortCrosswalk d on 
		a.patientsid=d.patientsid

	left join cdwwork.dim.loinc e on
		a.LOINCSID=e.LOINCSID;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;When I have the tables in the order above (abcde) I get:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;left join cdwwork.dim.loinc as e on&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;22&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;76&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, (, AS, ON.&lt;/P&gt;&lt;P&gt;&lt;EM&gt;I have other code that uses the same 3 part dataset name and it runs fine.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;When I switch the datasets around to acbde or abdce:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;left join CDWWork.dim.labchemtest as b on&lt;BR /&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;_&lt;BR /&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;22&lt;BR /&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;76&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;When in aebdc order:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;ERROR: Unresolved reference to table/correlation name c.&lt;BR /&gt;ERROR: Unresolved reference to table/correlation name e.&lt;BR /&gt;ERROR: The following columns were not found in the contributing tables: labchemcompletedatetime, labchemresultnumericvalue, LabChemTestName.&lt;BR /&gt;NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 28 Mar 2023 02:54:56 GMT</pubDate>
    <dc:creator>steffick</dc:creator>
    <dc:date>2023-03-28T02:54:56Z</dc:date>
    <item>
      <title>Proc Sql Errors are different based on the order of the tables that I am joining</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Errors-are-different-based-on-the-order-of-the-tables/m-p/866662#M342273</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm having problems with this piece of code. I get different errors when I change the order of the tables I'm left joining.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;
CONNECT TO SQLSVR AS CDW(DATAsrc=&amp;lt;project name&amp;gt; &amp;amp;SQL_OPTIMAL.);

create table scr0 as select scrssn, 
	labchemresultnumericvalue as num, 
	labchemcompletedatetime as res, 
	upper(LabChemTestName) as test_name, 
	upper(c.topography) as topography, e.loinc, 35 as dsslarno
	
 connection to cdw

(select d.scrssn, a.patientsid, labchemresultnumericvalue
as num, labchemcompletedatetime as res, 
upper(LabChemTestName) as test_name, 
upper(c.topography) as topography, e.loinc from

src.chem_labchem as a

	left join CDWWork.dim.labchemtest as  b on  
		a.LabChemTestSID=b.labchemtestsid

	left join CDWWork.dim.Topography as c  on 
		a.TopographySID=c.TopographySID) 

	left join Src.CohortCrosswalk d on 
		a.patientsid=d.patientsid

	left join cdwwork.dim.loinc e on
		a.LOINCSID=e.LOINCSID;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;When I have the tables in the order above (abcde) I get:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;left join cdwwork.dim.loinc as e on&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;22&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;76&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, (, AS, ON.&lt;/P&gt;&lt;P&gt;&lt;EM&gt;I have other code that uses the same 3 part dataset name and it runs fine.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;When I switch the datasets around to acbde or abdce:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;left join CDWWork.dim.labchemtest as b on&lt;BR /&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;_&lt;BR /&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;22&lt;BR /&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;76&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;When in aebdc order:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;ERROR: Unresolved reference to table/correlation name c.&lt;BR /&gt;ERROR: Unresolved reference to table/correlation name e.&lt;BR /&gt;ERROR: The following columns were not found in the contributing tables: labchemcompletedatetime, labchemresultnumericvalue, LabChemTestName.&lt;BR /&gt;NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 02:54:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Errors-are-different-based-on-the-order-of-the-tables/m-p/866662#M342273</guid>
      <dc:creator>steffick</dc:creator>
      <dc:date>2023-03-28T02:54:56Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql Errors are different based on the order of the tables that I am joining</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Errors-are-different-based-on-the-order-of-the-tables/m-p/866665#M342274</link>
      <description>&lt;P&gt;Your tables names are not valid SAS dataset names.&amp;nbsp; If you want to refer to a dataset with a name instead of quoted physical path you can use with a one level name (for a WORK or perhaps a USER datasets) or a two level name.&amp;nbsp; You cannot use a three level name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What datasets are you actually trying to query?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 03:09:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Errors-are-different-based-on-the-order-of-the-tables/m-p/866665#M342274</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-28T03:09:21Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql Errors are different based on the order of the tables that I am joining</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Errors-are-different-based-on-the-order-of-the-tables/m-p/866666#M342275</link>
      <description>&lt;P&gt;You aren't closing your passthrough query correctly and repeating your SQL logic in SAS SQL outside of the passthrough section isn't a good idea. Try something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
CONNECT TO SQLSVR AS CDW(DATAsrc=&amp;lt;project name&amp;gt; &amp;amp;SQL_OPTIMAL.);

create table scr0 as 
select *
	
 from connection to cdw

(select d.scrssn, a.patientsid, labchemresultnumericvalue
as num, labchemcompletedatetime as res, 
upper(LabChemTestName) as test_name, 
upper(c.topography) as topography, e.loinc from

src.chem_labchem as a

	left join CDWWork.dim.labchemtest as  b on  
		a.LabChemTestSID=b.labchemtestsid

	left join CDWWork.dim.Topography as c  on 
		a.TopographySID=c.TopographySID) 

	left join Src.CohortCrosswalk d on 
		a.patientsid=d.patientsid

	left join cdwwork.dim.loinc e on
		a.LOINCSID=e.LOINCSID
);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 03:34:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Errors-are-different-based-on-the-order-of-the-tables/m-p/866666#M342275</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-03-28T03:34:27Z</dc:date>
    </item>
  </channel>
</rss>

