BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jei
Quartz | Level 8 jei
Quartz | Level 8

Hi,

 

I have an issue regarding on converting the Julian datetime to datetime. The data are given below which is in julian datetime.

 

1465538477225
1465547195922
1465534266266
1465546595003
1465543587493
1465545693637
1465531252406

 

I want to ask how am I going to convert thesejulian datetime in ANYDTDTE20. format.

 

Thank you!

 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi @jei,

 

Your "Julian" datetime values seem to be numbers of milliseconds since January 1, 1970, 00:00:00, which makes the conversion easy:

data want;
input jdt;
dt=jdt/1000+'01JAN1970:0:0'dt;
d=datepart(dt);
t=timepart(dt);
format jdt 14.
       dt  datetime20.
       d   mmddyy10.
       t   e8601tm.;
cards;
1465538477225
1465547195922
1465534266266
1465546595003
1465543587493
1465545693637
1465531252406
;

proc print data=want;
run;

 

Edit:


jeideegertes wrote:

I want to ask how am I going to convert thesejulian datetime in ANYDTDTE20. format. 


 ANYDTDTE20. is an informat, not a format. It cannot be used to read values in your specific datetime format.

View solution in original post

8 REPLIES 8
PGStats
Opal | Level 21

What is the definition of those "Julian datetimes"? If they were expressed in seconds, the way SAS datetimes are, they would correspond to more than 46000 years. So they must be expressed in a smaller time unit.

PG
jei
Quartz | Level 8 jei
Quartz | Level 8

Julian Datetime also includes time, the hour, minutes, and seconds. The excel conversion of the following values are:

 

1465538477225  =  06/10/2016 06:01:17
1465547195922  =  06/10/2016 08:26:36
1465534266266  =  06/10/2016 04:51:06
1465546595003  =  06/10/2016 08:16:35
1465543587493  =  06/10/2016 07:26:27
1465545693637  =  06/10/2016 08:01:34
1465531252406  = 06/10/2016 04:00:52

 

How can I get the datetime values in SAS just like the result in excel?

 

Thank you!

Norman21
Lapis Lazuli | Level 10

I don't think SAS has a Julian datetime format or informat. In SAS, you will need to separate the values from Excel into dates and times; you can then translate the date part according to this:

 

http://support.sas.com/kb/38/811.html

Norman.
SAS 9.4 (TS1M6) X64_10PRO WIN 10.0.17763 Workstation

FreelanceReinh
Jade | Level 19

Hi @jei,

 

Your "Julian" datetime values seem to be numbers of milliseconds since January 1, 1970, 00:00:00, which makes the conversion easy:

data want;
input jdt;
dt=jdt/1000+'01JAN1970:0:0'dt;
d=datepart(dt);
t=timepart(dt);
format jdt 14.
       dt  datetime20.
       d   mmddyy10.
       t   e8601tm.;
cards;
1465538477225
1465547195922
1465534266266
1465546595003
1465543587493
1465545693637
1465531252406
;

proc print data=want;
run;

 

Edit:


jeideegertes wrote:

I want to ask how am I going to convert thesejulian datetime in ANYDTDTE20. format. 


 ANYDTDTE20. is an informat, not a format. It cannot be used to read values in your specific datetime format.

jei
Quartz | Level 8 jei
Quartz | Level 8

Hello @FreelanceReinhard,

That what I was looking for. I am also able to convert the other Julian dates.

Thank you very much!

If it is okay, I still have a question. I wanted to get the current date in which the format is similar to the Julian date format. How am I going to extract or get the current date?

Thank you!

FreelanceReinh
Jade | Level 19

You're welcome. So, you want to convert the current datetime to a Julian datetime value (in the sense of milliseconds since January 1, 1970, 00:00:00)?

 

data _null_;
jdt=round((datetime()-'01JAN1970:0:0'dt)*1000);
put jdt= 14.;
run;

The DATETIME function returns the current datetime as a SAS datetime value (seconds since January 1, 1960, 00:00:00).  I used the ROUND function to ensure integer results. On my Windows workstation, however, rounding to integers seems to be redundant, because the time precision (DATETIME() values) is limited to milliseconds anyway. I would still use the ROUND function (if I needed integer results) in order to avoid numeric representation issues.

 

The optional PUT statement writes the result to the log.

jei
Quartz | Level 8 jei
Quartz | Level 8
Hi @FreelanceReinhard,

No, what I mean is I wanted to get the current date. But when I'm getting it the resulted format is in Julian Datetime. That is, what I want is to get the current date (which is in Julian DateTime) in DateTime Function.
:))
FreelanceReinh
Jade | Level 19

Well, the current date as a SAS date value (number of days after January 1, 1960) is returned by the DATE (or TODAY) function. By default, a date does not contain a time component. To convert a date to a Julian datetime value, you have to specify a time value in addition to the date. In the data step below I use 00:00:00 as the time value, but feel free to replace it by something else (up to 23:59:59).

data _null_;
t='00:00:00't;
jdt=round((date()*86400+t-'01JAN1970:0:0'dt)*1000);
put jdt= 14.;
run;

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 8 replies
  • 5004 views
  • 3 likes
  • 4 in conversation