BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
y1232
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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;

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
ballardw
Super User

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.

Reeza
Super User

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;
y1232
Calcite | Level 5

Yes this actually worked - it does show a time of 4:00 am however it works for me!

Tom
Super User Tom
Super User

The extra 4 hours is probably because the date is using GMT and your system is in some other time zone.

 

 

Tom
Super User Tom
Super User

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.

 

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1621 views
  • 4 likes
  • 5 in conversation