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?
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?
Hi Reeza,
The SAS dataset already has MMDDYY10. format. How do I convert it to Date9. or a datetime format?
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.;
Thanks Reeza. I would definitely give it a try and let you know!
Here's the documentation explaining the default data type translations:
What is the mismatch you are getting?
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.