BookmarkSubscribeRSS Feed
steffick
Calcite | Level 5

Hi,

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.

proc sql;
CONNECT TO SQLSVR AS CDW(DATAsrc=<project name> &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;

When I have the tables in the order above (abcde) I get:

left join cdwwork.dim.loinc as e on

                                 22

                                 76
ERROR 22-322: Syntax error, expecting one of the following: a name, (, AS, ON.

I have other code that uses the same 3 part dataset name and it runs fine.

 

When I switch the datasets around to acbde or abdce:

left join CDWWork.dim.labchemtest as b on
                               _
                               22
                               76

When in aebdc order:

ERROR: Unresolved reference to table/correlation name c.
ERROR: Unresolved reference to table/correlation name e.
ERROR: The following columns were not found in the contributing tables: labchemcompletedatetime, labchemresultnumericvalue, LabChemTestName.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.

 

2 REPLIES 2
Tom
Super User Tom
Super User

Your tables names are not valid SAS dataset names.  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.  You cannot use a three level name.

 

What datasets are you actually trying to query?

 

SASKiwi
Opal | Level 21

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:

proc sql;
CONNECT TO SQLSVR AS CDW(DATAsrc=<project name> &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;

  

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 124 views
  • 0 likes
  • 3 in conversation