BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
newnoise
Fluorite | Level 6

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Peter_C
Rhodochrosite | Level 12

Just accept as datetime and use sas format DTDATE9.

That hides the time part

View solution in original post

2 REPLIES 2
Peter_C
Rhodochrosite | Level 12

Just accept as datetime and use sas format DTDATE9.

That hides the time part

newnoise
Fluorite | Level 6

Thanks! I figured it was an easy solution.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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