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.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.