Code · SAS
Julian dates in SAS
SAS has built-in functions for the ordinal Julian date (the
YYYYDDD day-of-year form used in manufacturing and IT), and a clean arithmetic
path to the astronomical Julian Day used in astronomy. This page covers
both, because they are two different things that share a name.
Two meanings of "Julian date"
The ordinal Julian date is a year plus the day-of-year:
2026202 (YYYYDDD) or 26202 (YYDDD). The
astronomical Julian Day is a continuous count of days since noon on
1 January 4713 BC — for example 2461242.5. SAS's DATEJUL,
JULDATE and the JULIAN informat all use the
ordinal meaning, not the astronomical one.
SAS date values, briefly
Internally a SAS date is an integer count of days since the SAS epoch,
1 January 1960. So SAS date 0 is 01JAN1960 and
today() returns that day count for the current date. Every conversion below is
just arithmetic or a function applied to that integer.
Ordinal Julian date (YYYYDDD)
The pairing to remember is JULDATE7() (SAS date → ordinal) and
DATEJUL() (ordinal → SAS date). JULDATE7() returns the 7-digit
yyyyddd form; JULDATE() returns the shorter yyddd form.
data _null_;
d = today(); /* SAS date value, e.g. 20656 */
jdate7 = juldate7(d); /* 2026202 (yyyyddd) */
jdate5 = juldate(d); /* 26202 (yyddd) */
put jdate7= jdate5=;
run; If you only need the day-of-year number on its own, subtract 1 January of the same year and add one:
data _null_;
d = today();
doy = d - mdy(1, 1, year(d)) + 1; /* 202 for 21JUL2026 */
put doy=;
run; Parsing an ordinal date back to a SAS date
Going the other direction, DATEJUL() takes a yyyyddd number and
returns a SAS date value. The JULIAN informat reads the same thing from text —
use julian7. for 7-digit input and julian5. for 5-digit input.
data _null_;
/* JULDATE7()/JULDATE() go SAS date -> ordinal;
DATEJUL() goes ordinal -> SAS date. */
d1 = datejul(2026202); /* from yyyyddd */
d2 = input('2026202', julian7.); /* JULIAN informat, 7-digit */
d3 = input('26202', julian5.); /* JULIAN informat, 5-digit */
put d1= date9. d2= date9. d3= date9.;
run; Astronomical Julian Day (JD) and MJD
SAS has no dedicated astronomical Julian Day function, but the conversion is a single
offset. SAS date 0 is 01JAN1960, whose Julian Day at 00:00 UTC is
2436934.5. So for any SAS date value d:
data _null_;
d = today(); /* SAS date value */
/* SAS date 0 = 01JAN1960, whose JD at 00:00 UTC = 2436934.5 */
jd = d + 2436934.5; /* astronomical Julian Day at midnight */
mjd = d + 36934; /* Modified Julian Day = JD - 2400000.5 */
put jd= mjd=;
run;
The Modified Julian Day falls out especially cleanly:
MJD = JD − 2400000.5 = d + 2436934.5 − 2400000.5 = d + 36934. In other words,
add 36934 to any SAS date to get its MJD.
Don't mix the two
DATEJUL, JULDATE/JULDATE7 and the
JULIAN informat all operate on the ordinal (day-of-year) Julian date.
They will never give you an astronomical Julian Day like 2461242.5 — for that,
use the d + 2436934.5 formula above.
Worked example — 21 July 2026
21 July 2026 is SAS date 20656, ordinal 2026202, astronomical JD
2461242.5 (at midnight UTC), and MJD 61242.
/* 21JUL2026 -> SAS date 20656 */
data _null_;
d = mdy(7, 21, 2026);
put d= date9.
"ordinal=" juldate7(d)
"jd=" (d + 2436934.5)
"mjd=" (d + 36934);
run;
/* d=20656 ordinal=2026202 jd=2461242.5 mjd=61242 */ See the Julian date converter to check any of these values, the Julian Day explainer for the astronomical system, or the code index for the same conversions in other languages such as Python and JavaScript.