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!
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.
If the values are integers, like 23480, you just assign the DATE9. format to this variable.
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.
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.
https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/... has a PDF with much information about dates you may find helpful.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.