温馨提示:本文翻译自stackoverflow.com,查看原文请点击:其他 - Oracle to_date with format J (Julian) in SAS
oracle sas to-date julian-date

其他 - SAS中Oracle格式为J(Julian)的to_date

发布于 2020-03-29 13:01:21

您知道有人如何将代表儒略日期的Oracle数字转换为SAS吗?我已经在SAS中有一个表,该表中有time_key列。在Oracle中,转换将是to_date(time_key, 'j')其中j代表朱利安。您知道如何在SAS中执行此操作吗?

SAS表示例:

TIME_KEY
 2456658
 2456689

预期产量:

TIME_KEY_DATE
 31DEC2013   
 31JAN2014

查看更多

查看更多

提问者
doremi
被浏览
147
Chris Long 2020-01-31 18:52

我对Oracle的Julian日期格式一无所知,但好像距SAS的“第0天”只有几天的距离。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日期值,然后应用所需的日期格式。