Code · SAS

Julian dates in SAS

SAS has built-in functions, an informat and a format for the day-of-year Julian date (yyyyddd and yyddd). The astronomical Julian Date and the JD Edwards CYYDDD form take one line of arithmetic each. This page covers all of them.

Two meanings of “Julian date”

The day-of-year Julian date is a year plus the day number: 2026202 (yyyyddd) or 26202 (yyddd). The astronomical Julian Date is a running count of days since noon UTC on January 1, 4713 BC, such as 2461242.5. DATEJUL, JULDATE, JULDATE7 and JULIANw. all use the day-of-year meaning.

SAS date values, briefly

A SAS date is the number of days since January 1, 1960, so '01JAN1960'd is 0 and '21JUL2026'd is 24308. A SAS datetime is the number of seconds since midnight on that day. Every conversion below is a function or simple arithmetic on those numbers.

Date to Julian date

JULDATE7() returns the 7-digit yyyyddd number and JULDATE() the 5-digit yyddd number:

data _null_;
  d      = today();        /* SAS date value: days since 01JAN1960 */
  jdate7 = juldate7(d);    /* 2026202 for 21JUL2026 (yyyyddd)    */
  jdate5 = juldate(d);     /* 26202                (yyddd)       */
  put jdate7= jdate5=;
run;

Both return numbers, so a date in 2000–2009 comes out as 5005 rather than 05005. When you need the padded text, use the JULIAN5. or JULIAN7. format:

data _null_;
  d = '05JAN2005'd;
  n = juldate(d);                 /* 5005: a number, so the leading zero is gone */
  put n=;                         /* n=5005                                      */
  put d julian5.;                 /* 05005: the JULIAN format keeps it           */
  put d julian7.;                 /* 2005005                                     */
  c = put(d, julian5.);           /* character variable '05005'                  */
run;

For the day of year on its own:

data _null_;
  d   = '21JUL2026'd;
  doy = d - mdy(12, 31, year(d) - 1);   /* 202 */
  put doy=;
run;

Julian date to a SAS date

DATEJUL() takes a numeric yyddd or yyyyddd value. The JULIAN informat reads the same thing from text: julian5. for 5 digits and julian7. for 7.

data _null_;
  d1 = datejul(2026202);              /* numeric yyyyddd -> SAS date */
  d2 = datejul(26202);                /* numeric yyddd, century from YEARCUTOFF= */
  d3 = input('2026202', julian7.);    /* character yyyyddd           */
  d4 = input('26202',   julian5.);    /* character yyddd             */
  put d1= date9. d2= date9. d3= date9. d4= date9.;
run;
/* d1=21JUL2026 d2=21JUL2026 d3=21JUL2026 d4=21JUL2026 */

Two-digit years are resolved with the YEARCUTOFF= system option, which names the first year of a 100-year window:

options yearcutoff=1940;   /* two-digit years read as 1940-2039 (the SAS 9.4 default) */

JD Edwards (CYYDDD) dates

JD Edwards stores dates as CYYDDD, with C counting centuries since 1900. Adding 1900000 turns it into yyyyddd, which DATEJUL already understands. JDE uses 0 for an empty date, so skip those:

data jde;
  input jde;
  /* JD Edwards CYYDDD -> SAS date: add 1900000 to get yyyyddd */
  if jde > 0 then d = datejul(jde + 1900000);
  /* and back */
  if not missing(d) then jde_again = juldate7(d) - 1900000;
  format d date9.;
  datalines;
126202
99365
0
;
run;
/* 126202 -> 21JUL2026, 99365 -> 31DEC1999, 0 -> missing (JDE's "no date") */

Astronomical Julian Date (JD) and MJD

SAS date 0 (January 1, 1960 at 00:00 UTC) is Julian Date 2436934.5, so the conversion is a single offset. A datetime value needs dividing by 86400 seconds first:

data _null_;
  d  = '21JUL2026'd;                     /* SAS date value          */
  dt = '21JUL2026:18:00:00'dt;           /* SAS datetime value, UTC */

  jd_date = d + 2436934.5;               /* JD at 00:00 UTC           */
  jdn     = d + 2436935;                 /* Julian Day Number         */
  mjd     = d + 36934;                   /* Modified Julian Date      */
  jd_time = dt / 86400 + 2436934.5;      /* JD with the time of day   */

  put jd_date= 12.1 jdn= mjd= jd_time= 12.2;
run;
/* jd_date=2461242.5 jdn=2461243 mjd=61242 jd_time=2461243.25 */

The Modified Julian Date follows directly: MJD = JD − 2400000.5 = d + 36934. Going back:

data _null_;
  jd  = 2461243.25;
  dt  = (jd - 2436934.5) * 86400;        /* SAS datetime value */
  d   = floor(jd - 2436934.5);           /* SAS date value     */
  put dt= datetime19. d= date9.;
run;
/* dt=21JUL2026:18:00:00 d=21JUL2026 */

Datetimes must be UTC

The Julian Date is defined in UTC. If your datetime values are local time, convert them first, for example with the TZONEU2S and TZONES2U functions in SAS 9.4M3 and later, or by subtracting the UTC offset in seconds.

Worked example: July 21, 2026

July 21, 2026 is SAS date 24308, yyyyddd 2026202, JDE 126202, Julian Date 2461242.5 at midnight UTC and MJD 61242. Expressions such as juldate7(d) cannot go directly in a PUT statement, so assign them to variables first:

data _null_;
  d       = mdy(7, 21, 2026);            /* SAS date 24308 */
  ordinal = juldate7(d);
  jde     = juldate7(d) - 1900000;
  jd      = d + 2436934.5;
  mjd     = d + 36934;
  put d= date9. ordinal= jde= jd= 12.1 mjd=;
run;
/* d=21JUL2026 ordinal=2026202 jde=126202 jd=2461242.5 mjd=61242 */

Check any value with the Julian date converter, read about the astronomical Julian Day, or see the same conversions in Python and SQL.

Frequently asked questions

How do I convert a Julian date to a date in SAS?

Use DATEJUL for a numeric value (d = datejul(2026202);) or the JULIAN informat for text (d = input('2026202', julian7.);). Then apply a date format such as DATE9. or MMDDYY10. to display it.

What is the difference between JULDATE and JULDATE7?

JULDATE7 always returns the 7-digit yyyyddd number. JULDATE returns the 5-digit yyddd number when the year falls in the 100-year window set by the YEARCUTOFF= option, and 7 digits otherwise. Because both return numbers, a 5-digit value for 2000 to 2009 loses its leading zero; use PUT(d, JULIAN5.) for text.

Does SAS have an astronomical Julian Date function?

No. The SAS Julian functions all use the day-of-year meaning. For the astronomical Julian Date, add 2436934.5 to a SAS date value (or divide a datetime value by 86400 first). For the Modified Julian Date, add 36934 to a SAS date.