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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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