I'm having an odd issue. I'm creating a new table in SQL server from SAS for one of my data sets. The date fields are saved in date9 format from original source. When this data gets uploaded to SQL, it is storing as a text field in YYYY-MM-DD for some reason and can't figure out why. Any suggestion or workarounds for this issue?
It is a standard Microsoft SQL Server database.
What SAS SQL Server database engine are you using? SQLSVR or ODBC? What version of MS SQL Server ODBC driver are you using? Older ODBC drivers sometimes have problems handling dates correctly.
If you're really sure that on the SAS side the variable is numerical and contains a SAS Date value then this is really an odd one.
With SAS not having a Date type the only way to detect date variables is via the format applied to the variable. I've experienced in the past that this didn't work properly with all SAS Date formats but it did always work when using formats DATE9 or DATETIME20. (...just the ones SAS creates when loading a DATE type from a DB into SAS).
May be run a proc contents against your source table to ensure the variable is of the correct type with the necessary format attached.
Also use OPTIONS SASTRACE=',,,d' SASTRACELOC=SASLOG NOSTSUFFIX; on top of the code to get a bit more information what's actually happening.
What you describe sounds like the process would have to identify the SAS column as containing a date but then create magically some numeric to text conversion logic (put on the SAS side or cast on the DB side). That would be really odd. Hopefully running your code with above options will tell us a bit more.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.