BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
steffick
Calcite | Level 5
Hi.
I have tried everything I could think of to resolve this error. Please check my code
to find the error I have made. First time poster.

Diane

%let pyr=15; %let yr=16; options obs=1000000; proc sql; CONNECT TO SQLSVR AS CDW(DATAsrc=xxxxxxxxxxxxxxxx &SQL_OPTIMAL.); create table test as select labchemresultnumericvalue, b.LabChemTestName,c.Topography from connection to cdw (select labchemresultnumericvalue, b.LabChemTestName,c.Topography from <project name>.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;); disconnect from cdw; quit;
log.png
c
1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

Try changing your first statement to:

create table test as select 
labchemresultnumericvalue,
LabChemTestName,Topography from

I removed the a. and b. table aliases.

 

Note that when you run code with explicit pass-through like this (it's a great feature to use), the code in parentheses is executed by the remote database. 

 

So this code:

(select labchemresultnumericvalue,
b.LabChemTestName,c.Topography from

<project name>.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;)

runs on SQL server.  SAS doesn't know about this code, and doesn't execute it.

 

The first part of your code which is not in the parentheses will be run by SAS:

create table test as select 
labchemresultnumericvalue,
b.LabChemTestName,c.Topography from

But  since the SAS code doesn't define an alias named a or b, it throws an error.

 

BASUG is hosting free webinars ! Next up: Art Carpenter on February 28 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

View solution in original post

2 REPLIES 2
Quentin
Super User

Try changing your first statement to:

create table test as select 
labchemresultnumericvalue,
LabChemTestName,Topography from

I removed the a. and b. table aliases.

 

Note that when you run code with explicit pass-through like this (it's a great feature to use), the code in parentheses is executed by the remote database. 

 

So this code:

(select labchemresultnumericvalue,
b.LabChemTestName,c.Topography from

<project name>.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;)

runs on SQL server.  SAS doesn't know about this code, and doesn't execute it.

 

The first part of your code which is not in the parentheses will be run by SAS:

create table test as select 
labchemresultnumericvalue,
b.LabChemTestName,c.Topography from

But  since the SAS code doesn't define an alias named a or b, it throws an error.

 

BASUG is hosting free webinars ! Next up: Art Carpenter on February 28 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
steffick
Calcite | Level 5
Thank you very much.
Diane

sas-innovate-2024.png

 

Secure your spot at the must-attend AI and analytics event of 2024: SAS Innovate 2024! Get ready for a jam-packed agenda featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events.

 

Register by March 1 to snag the Early Bird rate of just $695! Don't miss out on this exclusive offer. 

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 2 replies
  • 421 views
  • 0 likes
  • 2 in conversation