BookmarkSubscribeRSS Feed
PaigeMiller
Diamond | Level 26

We access a database via SAS, we work with a variable that is numeric and has format date9. and is listed as Transcode='No'. A contractor who works in some other part of the world (I really don't know where) access the same database via SAS and this exact same variable is listed as Text and Transcode='Yes'. How can this happen, and more importantly, how do we fix this?

--
Paige Miller
9 REPLIES 9
Ksharp
Super User

In genereal, numeric type variable no need to "Transcode" ,so you get Transcode='No'.
But for your contractor,maybe another story, maybe he/she use some options(or use different database driver/client) to convert this numeric type variable into character type . Like:

data have;
set database.have(dbsastype=( num_var='char(20)' ));
run;


And you can let contractor convert it to be numeric type by:
data have;
set database.have(dbsastype=( num_var='num' ));
run;

Anothe option is DBTYPE for SAS to DB. Check DOC of DBSASTYPE and DBTYPE at support.sas.com

Tom
Super User Tom
Super User

What database?

There are a number of databases now (thinking of Redshift and Snowflake) that allow you to define something that acts like a database but is really a collection of text files.  When you access the "tables" the database makes up the metadata on the fly.  So language options like which order to display month number and day number in date strings might cause the same text file to be read as valid dates by one and invalid dates (hence text strings) by another.

PaigeMiller
Diamond | Level 26

The data base is only listed as SQL Server.

--
Paige Miller
whymath
Lapis Lazuli | Level 10
Maybe contractor can not read date with format date9., try an international format, like e8601da.
Patrick
Opal | Level 21

@PaigeMiller The usual question is like always: "What's different between the two runs?"
1. Is this running identical code?

2. Are you using the same or different SAS Servers?

3. What's the database?

4. Is it a distributed database with potentially region specific views?

 

I feel @Tom is onto something here. 

You could via explicit pass-through verify if the data type is the same on the DB side as well as get the db local. 

Then on the SAS side I'd compare again settings like the local. If there are no differences then you would likely need to look into the drivers and the like. 

PaigeMiller
Diamond | Level 26

@Patrick wrote:

@PaigeMiller The usual question is like always: "What's different between the two runs?"
1. Is this running identical code?

2. Are you using the same or different SAS Servers?

3. What's the database?

4. Is it a distributed database with potentially region specific views?

 

I feel @Tom is onto something here. 

You could via explicit pass-through verify if the data type is the same on the DB side as well as get the db local. 

Then on the SAS side I'd compare again settings like the local. If there are no differences then you would likely need to look into the drivers and the like. 


1. Yes

2. No SAS server, this is base SAS 9.4

3. SQL Server

4. I doubt it, but can't say for sure.

 

Will try passthru

--
Paige Miller
ballardw
Super User

My first though was "show me the code" and how they connect.

 

I was wondering if one is using ODBC (the one getting character values) and another one of the SAS/ACCESS connections.

Patrick
Opal | Level 21

@PaigeMiller wrote:

@Patrick wrote:

@PaigeMiller The usual question is like always: "What's different between the two runs?"
1. Is this running identical code?

2. Are you using the same or different SAS Servers?

3. What's the database?

4. Is it a distributed database with potentially region specific views?

 

I feel @Tom is onto something here. 

You could via explicit pass-through verify if the data type is the same on the DB side as well as get the db local. 

Then on the SAS side I'd compare again settings like the local. If there are no differences then you would likely need to look into the drivers and the like. 


1. Yes

2. No SAS server, this is base SAS 9.4

3. SQL Server

4. I doubt it, but can't say for sure.

 

Will try passthru


There must be a difference either on the Server side (SQL Server), connection (driver) or client side (SAS). 

I'm not aware of any such differences that would cause a SQL Server date column to become Character on the SAS side so I'd also first verify that the data types on the SQL server side are the same using code similar to below:

libname yourlib sqlsrv ....;

proc sql;
  connect using yourlib;
  select * from connection to yourlib
    (
  SELECT *
    FROM 
      INFORMATION_SCHEMA.COLUMNS
    WHERE 
      TABLE_SCHEMA = '<schema>' 
      AND TABLE_NAME = '<table>'
      and COLUMN_NAME='<column>'
    );
  disconnect from yourlib;
quit;

I'd be running this test via SAS using the exactly same libname definition as in the code with the issues to ensure we're accessing the exact same table or view.

Quentin
Super User

In addition to the question of what database is it, what is the type of the column when viewed with the native database tools?

 

Further possible testing: If you create a new test table with in the database with a column of the same type and just a few values, can you replicate the problem? Will a new test database on the same server replicate the problem?  Will a test database on a different server replicate the problem?

The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 9 replies
  • 496 views
  • 5 likes
  • 7 in conversation