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