Oracle to_date 在 SAS 中格式为 J (Julian)

Oracle to_date with format J (Julian) in SAS

你知道有人如何将代表 Julian 日期的 Oracle 数字转换为 SAS 吗?我已经在 SAS 中有一个 table,它有 time_key 列。在 Oracle 中,转换为 to_date(time_key, 'j'),其中 j 代表 Julian。你知道如何在 SAS 中执行此操作吗?

SAS table 示例:

TIME_KEY
 2456658
 2456689

预期输出:

TIME_KEY_DATE
 31DEC2013   
 31JAN2014

我对 Oracle 的 Julian 日期格式一无所知,但它似乎只是一些 'day 0' 中的天数,就像在 SAS 中一样。 SAS 中的第 0 天是 01JAN1960,所以我们只需要计算出 Oracle 系统(其中 31DEC2013 是天数 2456658)与 SAS 系统(其中 31DEC2013 是 22280)之间的偏移量:

data dates;
  time_key = 24566658; output;
  time_key = 24566689; output;
run;

* Calculate the offset, given 24566658 is 31-Dec-2013;
data _null_;
  call symput("offset", 24566658 - "31DEC2013"d);
run;

%put Offset from SAS dates to Oracle dates is &offset days;

data converted;
  set dates;
  * Adjust the Oracle date values by subtracting the calculated offset;
  sas_time_key_numeric = time_key - &offset;
  sas_time_key = put(time_key - &offset, date9.);
  put time_key= sas_time_key_numeric= sas_time_key=;
run;

输出为:

10   %put Offset from SAS dates to Oracle dates is &offset days;
Offset from SAS dates to Oracle dates is     24546935 days
11
12   data converted;
13     set dates;
14     sas_time_key_numeric = time_key - &offset;
15     sas_time_key = put(time_key - &offset, date9.);
16     put time_key= sas_time_key_numeric= sas_time_key=;
17   run;

time_key=24566658 sas_time_key_numeric=19723 sas_time_key=31DEC2013
time_key=24566689 sas_time_key_numeric=19754 sas_time_key=31JAN2014

给出了正确的转换。

所以幻数是24546935;从您的 Oracle 日期中减去它以获得相应的 SAS 日期值,然后应用您想要的日期格式。