Good day
A datetime field was incorrectly stored (into a new table) as numeric 8.
Original Date value of 9 July 2019 is stored as 1878249600. I think this includes the date and time.
How do I convert the numeric field back to a datetime or date9 field.
Simply use an appropriate format to display the value correctly. And use the Datepart Function to display the value as a date
data _null_;
dt=1878249600;
d =datepart(dt);
put dt = datetime20. // d= date9.;
run;
Result:
dt=09JUL2019:00:00:00 d=09JUL2019
Just apply a SAS datetime format to the variable. For example:
format MyDatetime datetime22.2;
Thanks Patrick
I tried it and it works.
Sometimes the simplest answer is the best. I was trying many different ways to convert the number to a date and in the end it just needed to be formatted.
SAS date and datetime values are stored as numeric and a length of 8 is correct as well. The number you see looks like a SAS datetime value which is nothing else than the count of seconds since 1/1/1960.
The only thing you need to do is apply a SAS format to the numerical column so your SAS datetime value becomes human readable. Here the docu explaining this much better than I can.
data test;
dttm=1878249600;
dttm2=dttm;
dttm3=dttm;
format dttm2 datetime21. dttm3 B8601DN10.;
output;
stop;
run;
proc print data=test;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.