BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Anotherdream
Quartz | Level 8

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!

1 ACCEPTED SOLUTION

Accepted Solutions
LinusH
Tourmaline | Level 20

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

3 REPLIES 3
ballardw
Super User

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.

ChrisBrooks
Ammonite | Level 13

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

LinusH
Tourmaline | Level 20

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 1211 views
  • 1 like
  • 4 in conversation