DATA Step, Macro, Functions and more

ODBC connection and character dates

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

ODBC connection and character dates

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!


Accepted Solutions
Solution
‎10-15-2013 01:23 PM
Valued Guide
Posts: 2,175

Re: ODBC connection and character dates

Just accept as datetime and use sas format DTDATE9.

That hides the time part

View solution in original post


All Replies
Solution
‎10-15-2013 01:23 PM
Valued Guide
Posts: 2,175

Re: ODBC connection and character dates

Just accept as datetime and use sas format DTDATE9.

That hides the time part

Occasional Contributor
Posts: 7

Re: ODBC connection and character dates

Thanks! I figured it was an easy solution.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 620 views
  • 0 likes
  • 2 in conversation