BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Jyuen204
Obsidian | Level 7

I am referencing a table for some data and the table contains a date field but it is set in a SAS Date format:
23480
23481
23482 etc

 

I want to query the data and pull it with Date9 format

 

I tried :
SELECT DATEPART(RT_DATE) AS PERIOD_DT format = date9.

 

but it returns with the base SAS date (Jan 1 1960)

Is there another method to use in my select to get the date to convert? Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

The DATEPART function assumes that you are extracting a Date value from a DATETIME value. DATETIME values are numbers of seconds and dates are numbers of days. So when you apply the Datepart to a date you get a very much smaller result. Basically any date between 01JAN1960 and 20JUL2196 will return a "datepart" value of 01JAN1960.

 

Your numeric value of 23480 is 14APR2024. So applying datepart to it will result in 01JAN1960.

So you apparently have date values and using Datepart is not wanted or needed. Just apply the date9. format to that variable.

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

If the values are integers, like 23480, you just assign the DATE9. format to this variable.

--
Paige Miller
Tom
Super User Tom
Super User

Why did you treat the values as if they were DATETIME values instead of DATE values?

SAS stores datetime values in seconds and date values in days.

 

The number 23,480 is  01JAN1960:06:31:20 when treated as a count of seconds but it is 14APR2024 when treated as a count of days.

Jyuen204
Obsidian | Level 7
I was not aware that I did. I am simply looking for a select option to get a date9. date from a source table that has the date values in SAS format
ballardw
Super User

The DATEPART function assumes that you are extracting a Date value from a DATETIME value. DATETIME values are numbers of seconds and dates are numbers of days. So when you apply the Datepart to a date you get a very much smaller result. Basically any date between 01JAN1960 and 20JUL2196 will return a "datepart" value of 01JAN1960.

 

Your numeric value of 23480 is 14APR2024. So applying datepart to it will result in 01JAN1960.

So you apparently have date values and using Datepart is not wanted or needed. Just apply the date9. format to that variable.

Jyuen204
Obsidian | Level 7
Thank you, that worked. I wasnt aware that was what the function was doing. Appreciate the guidance.

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
  • 6 replies
  • 232 views
  • 0 likes
  • 4 in conversation