DATA Step, Macro, Functions and more

Julian Dates conversion

Reply
Super Contributor
Posts: 268

Julian Dates conversion

Hi,

One of the datasets I am working with has julian dates. I am using the functions like this -

put(DATEJUL(x),mmddyy10.)

The query builder in EG is validating the function usage correctly but the output is like this -

01/01/7442

01/01/7445

01/01/7447

01/02/7445

01/02/7447

01/03/7442

01/03/7445

Any suggestions as to get the correct output?

Thanks,
Raj.

Super User
Posts: 17,912

Julian Dates conversion

try date=datejul(x);

format date date9.;

I don't think you ned the put and mmddyy10. portion.

Respected Advisor
Posts: 3,124

Re: Julian Dates conversion

I don't think format matters.

data _null_;

X=94365;/*x=1994365*/

a=put(datejul(x),mmddyy10.);

b=datejul(x);

put a;

put b / b date9.;

run;

OP, please show some raw data of your julian dates, as you can see, I can't repeat your problem.

Regards,

Haikuo

Super Contributor
Posts: 268

Julian Dates conversion

These are my two input fields-

input_dates.bmp

Trusted Advisor
Posts: 1,300

Julian Dates conversion

These values do not fit with a expected format for any definition of a julian date unless they are meant to be millenia in the future.  It looks like you may be dealing with a unix style time counter possibly, although that would put all the dates in your example in the 1970's.  What are your expected values for the data shown?

Super Contributor
Posts: 268

Julian Dates conversion

Thanks Friedegg, I see your point about the julian dates. My manager just forwarded me this link -

http://en.wikipedia.org/wiki/Julian_day_number

Either way, is there a funtion to get the appropriate mmddyy10. format? The dates are hospital admission/discharge dates around 2002-04.

Thanks,

Trusted Advisor
Posts: 1,300

Julian Dates conversion

I am very familiar with date systems, the JDN system, as I have mentioned does not fit this data.  The values you have would represent dates thousands of years in the future since it is representing a count of 7 million plus days (over 19,000 years) from Nov. 24, 4714 BC

I can say quite confidently that these data elements you have shared here are absoluelty not Julian Dates repseneting Gregorian dates in and around April 2002.

Trusted Advisor
Posts: 1,300

Re: Julian Dates conversion

This may be a case of mixed semantics.  The term julian date has two meanings, unfortunately.  One convention defines a julian date as a date in the format such as yy[yy]ddd such as 11001, which would be the first day or 2011 or 01/01/2011 would be your expected result.  The more common, in my mind, definition of a julian date is the count of days from the julian epoch (jdn 0 or Nov. 24, 4714 BC).  The Datejul function is expecting the definition I described first.  If you data is like the second definition I used then you can convert to a sas date by simple subtraction: put(x-2436934.5,mmddyy10.);

Super User
Posts: 10,538

Julian Dates conversion

If you can find the actual date associated with one of those numbers then you can adjust to use the base date that SAS uses.

Also I would look at the last 3 digits to see if the range is 001 to 366 (2004 was a leap year). If so it may be that the first 4 digits are some year coding scheme though your example would yield more than 3 calendar years.

Super Contributor
Posts: 268

Julian Dates conversion

Hi,

So we looked up similar files on the mainframe. They all seem to have the 2004123 date whereas only the sas file we got has these 7447153 dates. Also, the last 3 digits do fall into the 1-366 range. So, there is something odd with the first 4 digits only.

Thanks,
saspert.

Super User
Posts: 10,538

Julian Dates conversion

So it looks like there may be an issue with reading the data from the mainframe. At which point how it was transferrec becomes a question as native dates seem to be a recurring issue with data conversions.

I would suggest getting the minimum data from the mainframe if possible. The compare the minimum value from you SAS data set. If the minimum is 2004XXX and the minimum in SAS is 7444xxx then the year would be the value of the first four digits in the SAS dataset  - (7444-2004). Which  gives us a

year= floor(<sasvar>/1000) - (7444-2004);

days= mod(<sasvar>,1000);

date= datejul( year*1000+days);

Ask a Question
Discussion stats
  • 10 replies
  • 7191 views
  • 3 likes
  • 5 in conversation