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.

 

 

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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