今天給大家介紹幾個有用的SAS日期函數(shù):
(1)intnx function;
nextdt = intnx('Interval', start,n_interval);
/* 從開始dt返回間隔數(shù)的日期 */
(2)intck function;
intvl = intck('Interval', from, to);
/* 返回給定時間跨度內(nèi)的時間間隔數(shù)*/
(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);
/*返回日期變量或日期值的周數(shù)(第幾周) */
/ 測試程序 /
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;
/ 結(jié)果展示 /
-
SAS
+關(guān)注
關(guān)注
2文章
521瀏覽量
32834
發(fā)布評論請先 登錄
相關(guān)推薦
評論