SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Date datatype problem while exporting SAS data to SQL Server

Reply
Contributor
Posts: 40

Date datatype problem while exporting SAS data to SQL Server

Hi,

 

I am trying to export my SAS data sets to SQL Server. There are 3 date columns in my table. However, I am facing a data type mismatch issue. I have created an empty table with all required columns on SQL Server. The Date columns on SQL Server have the datatype Date. Please find below my code to transfer SAS data to SQL Server:

 

proc sql;

Connect to odbc(datasrc="data" user=Writer password=Writer);

INSERT INTO SQL.Database

SELECT *

FROM SAS.Database

WHERE ID IS NOT NULL;

disconnect from odbc;

Quit;

 

Please find code I used on SQL server to create blank table (there are more columns than these three):

 

CREATE TABLE database

(

START_DATE Date,

END_DATE Date,

REPORT_DATE Date,

);

 

The format and informat of SAS Date columns is MMDYY10. How do I move data from SAS Date columns to the three Date columns on SQL Server?

 

 

Super User
Posts: 17,929

Re: Date datatype problem while exporting SAS data to SQL Server

I'm assuming you've already searched and tried the standard solutions. 

 

So what happens if you use Date9 or a datetime type/format instead?

Contributor
Posts: 40

Re: Date datatype problem while exporting SAS data to SQL Server

Hi Reeza,

 

The SAS dataset already has MMDDYY10. format. How do I convert it to Date9. or a datetime format?

Super User
Posts: 17,929

Re: Date datatype problem while exporting SAS data to SQL Server

Apply a format...

 

That code you showed wouldn't work, because when you use SQL pass through you don't have access to your SAS Database.

 

Format variable_name date9.;

 

Contributor
Posts: 40

Re: Date datatype problem while exporting SAS data to SQL Server

Thanks Reeza. I would definitely give it a try and let you know!

 

Super User
Posts: 3,115

Re: Date datatype problem while exporting SAS data to SQL Server

[ Edited ]

Here's the documentation explaining the default data type translations:

 

http://support.sas.com/documentation/cdl/en/acreldb/69580/HTML/default/viewer.htm#n0h4i25zq3t58en1lg...

 

What is the mismatch you are getting?

 

Ask a Question
Discussion stats
  • 5 replies
  • 143 views
  • 0 likes
  • 3 in conversation