我对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日期值,然后应用所需的日期格式。
非常酷的解决方案,谢谢!