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;
... View more