BookmarkSubscribeRSS Feed
saspert
Pyrite | Level 9

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.

10 REPLIES 10
Reeza
Super User

try date=datejul(x);

format date date9.;

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

Haikuo
Onyx | Level 15

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

saspert
Pyrite | Level 9

These are my two input fields-

input_dates.bmp

FriedEgg
SAS Employee

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?

saspert
Pyrite | Level 9

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,

FriedEgg
SAS Employee

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.

FriedEgg
SAS Employee

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.);

ballardw
Super User

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.

saspert
Pyrite | Level 9

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.

ballardw
Super User

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);

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 10 replies
  • 14344 views
  • 3 likes
  • 5 in conversation