why some where conditions dont work on sql passthrough

Accepted Solution Solved
Reply
Super Contributor
Posts: 418
Accepted Solution

why some where conditions dont work on sql passthrough

Hello, I was just asked a question from a colleague that I honestly didn't know how to answer, or if my impression is even correct.

So sometimes when you define a libname to a sql databse (like below)

libname testy odbc dsn='mymadeupdsn' schema=dbo bulkload=yes dbmax_text=32000;

and you try to run the following code it fails.

data answer;

set testy.Tabledata;

where missing(acctno)=0;

run;

It is my understanding (PLEASE correct me if I am wrong) that sas tries to pass the syntax for the function in question over to the sql database when you use a where clause, and maybe sql server doesn't understand this function so it fails.

can anyone point me to a paper illustrating this, and or an option that would allow me to see what exact syntax is being passed to the database (and what is being returned). I am well aware of pass through functionality, and I know this is not the best way to do this, but It was a question that was asked that I frankly froze on.

Thanks for your help!


Accepted Solutions
Solution
‎06-11-2014 03:23 AM
Super User
Posts: 5,260

Re: why some where conditions dont work on sql passthrough

options sastrace=',,,d' sastraceloc=saslog;

will let you know if/how your where-clase will be translated to in ODBC SQL.

Using NOT NULL or similar would make it more likely for implicit pass-thru.

Data never sleeps

View solution in original post


All Replies
Super User
Posts: 10,548

Re: why some where conditions dont work on sql passthrough

Did you try

Where not missing(acctno);

also many databases really don't understand Missing the way SAS does but will report NULL or similar. You may need to find out what the specific data base uses and use something like

Where acctno ne 'NULL';

Unless it is a serious performance issue it may be easier to read in all of the data and filter on the output data set after you know what values are coming in.

data answer (where=( acctno ne 'NULL')); after looking at some of the data for acctno.

Regular Contributor
Posts: 190

Re: why some where conditions dont work on sql passthrough

I've never used SQL Server so I can't help you with the specifics about how it handles null (or in SAS terms missing) values but you might find more luck if you used explicit passthrough rather than letting the ODBC engine do the conversion work.

Chris

Solution
‎06-11-2014 03:23 AM
Super User
Posts: 5,260

Re: why some where conditions dont work on sql passthrough

options sastrace=',,,d' sastraceloc=saslog;

will let you know if/how your where-clase will be translated to in ODBC SQL.

Using NOT NULL or similar would make it more likely for implicit pass-thru.

Data never sleeps
🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 200 views
  • 1 like
  • 4 in conversation