Solved
Contributor
Posts: 60

how to convert Julian to YYYY MM DD ?

Hi,

I am facing an issue regarding date conversion. I have a date which is in CYYDDD format It's nothing but a JULIAN format of the date.

Date are given below

114010

14001

I need to convert this date into YYYYMMDD format But I can't see any function which can help to convert it required format.

I am using below method to convert it.which helping me to convert 14001 in req format

req_date=tranwrd(put(dhms(input(put(given_date,6.),JULIAN6.),reqt_hh,reqt_mm,reqt_ss),E8601DT21.),'T',' ');

Please let me know how to convert first julian date

Accepted Solutions
Solution
‎12-25-2014 02:39 PM
Contributor
Posts: 60

Re: how to convert Julian to YYYY MM DD ?

Thanks for your help and it's really helpfull.I achieved it by doing below.

Let me if you see any loophole in my code.

data auth;

input AU_TRANS_DATE_JUL;

datalines;

114010

14010

;

run;

data req_date;

set auth(keep=AU_TRANS_DATE_JUL reqt_hh reqt_mm reqt_ss);

if AU_TRANS_DATE_JUL>100000 then

auth_trans_date=tranwrd(put(dhms(datejul(1900000+AU_TRANS_DATE_JUL),reqt_hh,reqt_mm,reqt_ss),E8601DT21.),'T',' ');

else

auth_trans_date=tranwrd(put(dhms(input(put(AU_TRANS_DATE_JUL,6.),JULIAN6.),reqt_hh,reqt_mm,reqt_ss),E8601DT21.),'T',' ');

run;

All Replies
Super User
Posts: 24,010

Re: how to convert Julian to YYYY MM DD ?

What output are you expecting

1) Exact dates for your sample

2) SAS date with format applied or character variable

Contributor
Posts: 60

Re: how to convert Julian to YYYY MM DD ?

I am expecting an output in YYYY MM DD HH MM SS format.HH MM SS will taken care by reqt_hh,reqt_mm,reqt_ss variable.Let me know if you have any query.

Super User
Posts: 10,850

Re: how to convert Julian to YYYY MM DD ?

If that variable is date type variable , why not assign it another format mmddyyn10. ?

format  given_date  mmddyyn10.  ;

Contributor
Posts: 60

Re: how to convert Julian to YYYY MM DD ?

Hi,

It's in Julian format with six digit. there are function like Datejul which will help to convert it into Date.But that is for 5 0r 7 digit not for 6 digit.

Super User
Posts: 24,010

Re: how to convert Julian to YYYY MM DD ?

You have inconsistent data which makes it manual, especially if both of your example dates are in 2014.

Here's a manual way, basically remove the first digit as it doesn't seem to add any information.

data have;

input given_date @@;

cards;

114010

14001

;

run;

data want;

set have;

char_var=put(given_date, 6. -l);

if length(char_var)>5 then char_var=substr(char_var, 2);

req_date=input(char_var,JULIAN7.);

format req_date date9.;

run;

Solution
‎12-25-2014 02:39 PM
Contributor
Posts: 60

Re: how to convert Julian to YYYY MM DD ?

Thanks for your help and it's really helpfull.I achieved it by doing below.

Let me if you see any loophole in my code.

data auth;

input AU_TRANS_DATE_JUL;

datalines;

114010

14010

;

run;

data req_date;

set auth(keep=AU_TRANS_DATE_JUL reqt_hh reqt_mm reqt_ss);

if AU_TRANS_DATE_JUL>100000 then

auth_trans_date=tranwrd(put(dhms(datejul(1900000+AU_TRANS_DATE_JUL),reqt_hh,reqt_mm,reqt_ss),E8601DT21.),'T',' ');

else

auth_trans_date=tranwrd(put(dhms(input(put(AU_TRANS_DATE_JUL,6.),JULIAN6.),reqt_hh,reqt_mm,reqt_ss),E8601DT21.),'T',' ');

run;

Super User
Posts: 24,010

Re: how to convert Julian to YYYY MM DD ?

My only concern is are you sure that

14010 isn't January 10, 1914?

I don't know your data, but that's still a valid birthdate in my data.

(Also, it changed from initial example: 14010 vs 14001).

Contributor
Posts: 60

Re: how to convert Julian to YYYY MM DD ?

I agreed on your concern.Even I have the same concern.But the data on which I am working belong to 2014 January month data.

Due to which I am feeling little bit comfortable with the conversion.

Super User
Posts: 24,010

Re: how to convert Julian to YYYY MM DD ?

Date are given below

114010

14001

What dates are the above?

Jan 10, 2014

Jan 1, 2014?

Contributor
Posts: 60

Re: how to convert Julian to YYYY MM DD ?

114010 date is 2014-01-10

Posts: 3,186