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
PROC Star

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-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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