- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
SAS 9.4 (TS1M6) X64_10PRO WIN 10.0.17763 Workstation
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
:))
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;