我有一个sql语句来提取日期对象。它在Postgres中运行良好,但不是sas。部分查询是这样的:
(case when date_part('month',run_date)::integer < 10
THEN '0'||
date_part('month',run_date)::varchar(1)||
date_part('year',run_date)::varchar(4)
else date_part('month',run_date)::varchar(2)||date_part('year',run_date)::varchar(4)
end) as our_date
在sas中,没有date_part函数。我试过datepart函数。但它没有执行相同的功能。我怎么能在sas中运行sql语句?感谢。
答案 0 :(得分:11)
data have;
timestamp='01JAN2012:08:48'dt;
run;
proc sql;
select datepart(timestamp) format=mmddyy10.,
timepart(timestamp) format=time.,
month(datepart(timestamp)),
year(datepart(timestamp))
into :date , :time, :month, :year
from have;
quit;
%put DATE: &date;
%put TIME: &time;
%put MONTH: &month;
%put YEAR: &year;
答案 1 :(得分:0)
我认为你可以使用
MONTH(run_date)
和
YEAR(run_date)