电子说
今天给大家介绍几个有用的SAS日期函数:
(1)intnx function;
nextdt = intnx('Interval', start,n_interval);
/* 从开始dt返回间隔数的日期 */
(2)intck function;
intvl = intck('Interval', from, to);
/* 返回给定时间跨度内的时间间隔数*/
(3)datepart function;
date=datepart(sasdt);
/* 从SAS日期时间值中提取日期 */
(4)timepart function;
date=timepart(sasdt);
/* 从SAS日期时间值中提取时间 */
注:‘Interval’ can be year, month, day, week, qtr.
(5)year function;
year = year(sasdt);
/* return year of the sas date */
**(6)month function; **
month=month(sasdt);
/*return month of the sas date */
(7)day function ;
day = day(sasdt);
return day of the sas date /
(8)qtr function;
qtr = qtr(sasdt);
/ return 季度 of the sas date /
(9)weekday function;
wkd=weekday(sasdt);
/*return day of the week of the sas date */
(10)week function;
wkd=week(sasdt);
/*返回日期变量或日期值的周数(第几周) */
/ 测试程序 /
data null ;
sasdt='08jan2007'd;
put 'date= ' sasdt yymmdd10.;
year=year(sasdt);
put 'year= ' year;
month=month(sasdt);
put 'month=' month;
day =day(sasdt);
put 'day =' day;
qtr =qtr(sasdt);
put 'qtr =' qtr;
weekday=weekday(sasdt);
put 'Weekday='weekday;
today=today();
put 'Today is: ' today date9.;
dt1='01jan2006'd;
put 'date1=' dt1 date9.;
dt2='01jan2007'd;
put 'date2=' dt2 date9.;
intervald=intck('day',dt1, dt2);
put "intervald =" intervald;
intervalm=intck('month',dt1, dt2);
put "intervalm=" intervalm;
intervaly=intck('year',dt1, dt2);
put "intervaly=" intervaly;
datetime='08JAN2007:09:00:00'dt;
put 'datetime=' datetime datetime20.;
datepart=datepart(datetime);
put 'datepart=' datepart date9.;
timepart=timepart(datetime);
put 'timepart=' timepart date9.;
run;
/ 结果展示 /
全部0条评论
快来发表一下你的评论吧 !