I'm trying to pull data from an ODBC connection (SQL Server), and whenever I pull a date variable, it's coming into SAS as character rather than as numeric. Here's the code I'm using:
PROC SQL;
CONNECT TO ODBC(DSN='SQL Server');
CREATE TABLE demogs AS
SELECT *
FROM CONNECTION TO ODBC
(
SELECT
customer_id,
convert(date,birthdate) as birthdate
);
QUIT;
The birthdate field comes into SAS as a character variable (e.g., "1986-10-08"). How can I get the imported character date value to be numeric? The reason the "convert" statement is used in the SQL code is that the original date value is in DATETIME, but there is NO time on any of the date values. Thus, I'd prefer to just pull in the month, day, and year and drop the time element (which is always 00:00:00:000) altogether.
I'm sure this is probably a common enough problem, but after searching through the forums (and elsewhere online), I wasn't able to find an issue that touched on this specific ODBC connection problem.
Any help would be greatly appreciated. Thanks!
Just accept as datetime and use sas format DTDATE9.
That hides the time part
Just accept as datetime and use sas format DTDATE9.
That hides the time part
Thanks! I figured it was an easy solution.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.