Hi,
Looking to see how to convert a 11 digit number to a date value?
Example:
1685937600
I tried this code -
data test;
xdate = put(1685937600, datetime20.);
run;
However my output is 04JUN2013:04:00:00
When it should be June 5th 2023
Your date is using a starting base of 01Jan1970, but SAS uses 01Jan1960.
Not sure if there's an easier fix than this.
options c
data test;
x=1685937600;
xdate = put(1685937600, datetime20.);
xdate2 = x + dhms('01Jan1970'd,0,0,0)-dhms('01Jan1960'd,0,0,0);
format xdate2 datetime20.;
run;
proc print;run;
I don't see how this value of 1685937600 can be June 5, 2023. You need to explain how you got June 5, 2023 as the correct answer.
Why do you think that value should be 5 Jun 2023? Where did that 11 digit value come from?
If a datetime value is supposed to be 5 Jun 2023 it would start at 2001542400.
If a value is a datetime, i.e. with seconds involved, you could request the SAS date value using the DATEPART function, and assign a date format for readability. That value with the Datepart function will return 4 Jun 2013 though.
Your date is using a starting base of 01Jan1970, but SAS uses 01Jan1960.
Not sure if there's an easier fix than this.
options c
data test;
x=1685937600;
xdate = put(1685937600, datetime20.);
xdate2 = x + dhms('01Jan1970'd,0,0,0)-dhms('01Jan1960'd,0,0,0);
format xdate2 datetime20.;
run;
proc print;run;
Yes this actually worked - it does show a time of 4:00 am however it works for me!
The extra 4 hours is probably because the date is using GMT and your system is in some other time zone.
There is no need to make the function call just use a datetime literal instead of date literal.
xdate2 = x + '01Jan1970:00:00:00'dt;
Also there is no need to subtract the zero from the result.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: