【轉載】SAS INTNX詳解

2010-06-13 15:30:39|  分類: 統計知識 |  標籤: |舉報 |字號 訂閱

在時間序列分析中,INTNX是比較常用的函數,用於輸入時間。

形式如:INTNX(interval,start-from, increment) 。書上的用法一貫比較簡單,網上搜索一下,該函數至少包括以下幾種用法。

 

Example1. Some simple examples of using INTNX function:


format day week month_ year date9.;
 
day=intnx('day', '01FEB2010'd, 7); 
week=intnx('week', '01FEB2010'd, 1); 
month_=intnx('month', '01FEB2010'd, 2); 
year=intnx('year', '01FEB2010'd, 1); 

結果:


day = 08FEB2010 (+7 days)
week = 07FEB2010 (next Sunday)
month_ = 01APR2010 (next 1st day of 2nd next month)
year = 01JAN2011 (next 1st day of next year)


Example2. Multiplying and shifting intervals.

You may change the first argument (interval) by adding digits as in the example below.


format day week year date9.;
 
day=intnx('day2', '01FEB2010'd, 2); 
week=intnx('week1.3', '01FEB2010'd, 1); 
year=intnx('year1.3', '01FEB2010'd, 1); 

結果:


day = 05FEB2010 (+2 days twice)
week = 02FEB2010 (Next Tuesday)
year = 01MAR2011 (Next Year's third month (March) 1st day)

You are free to combine intervals by multiplying and shifting it. However, please be careful when contructing complex interval specifications.

 

Example3. Datetime and time formats.

The INTNX function may cope with datetime, time and date formats. The above examples are based on date format. The example below uses datetime and time formats.


format seconds minutes hours days weeks datetime20.;
format t_seconds t_minutes t_hours time9.;
 
seconds=intnx('second', '01FEB2010:00:00:00'dt, 1); 
minutes=intnx('minute', '01FEB2010:00:00:00'dt, 1); 
hours=intnx('hour', '01FEB2010:00:00:00'dt, 1); 
days=intnx('dtDay', '01FEB2010:00:00:00'dt, 1); 
weeks=intnx('dtWeek', '01FEB2010:00:00:00'dt, 1);
 
t_seconds=intnx('second', '00:00:00't, 1); 
t_minutes=intnx('minute', '00:00:00't, 1); 
t_hours=intnx('hour', '00:00:00't, 1);

結果:


seconds= 01FEB2010:00:00:01 (next second)
minutes= 01FEB2010:00:01:00 (next minute)
hours= 01FEB2010:01:00:00 (next hour)
days= 02FEB2010:00:00:00 (next day)
weeks= 07FEB2010:00:00:00 (next Sunday)
t_seconds = 00:00:01 (next second)
t_minutes = 00:01:00 (next minute)
t_hours = 01:00:00 (next hour)

and so on.

 

Example4. Alignment within the interval.


format beginning middle end sameday date9.;
 
beginning=intnx('month', '05FEB2010'd, 1, 'b'); 
middle=intnx('month', '05FEB2010'd, 1, 'm');  
end=intnx('month', '05FEB2010'd, 1, 'e'); 
sameday=intnx('month', '05FEB2010'd, 1, 's');

結果


beginning = 01MAR2010 (1st day of the next month)
middle= 16MAR2010 (middle day (16 of 31) of the next month)
end= 31MAR2010 (last day (31) of the next month)
sameday = 05MAR2010 (the same day (5) of the next month)

但是我這個程序竟然有問題,誰能解答?

data exp1;
input a1 @@;
m=_n_;
dt=intnx('hour','1jan1996:12:10:00'dt,_n_-1);
format dt DATETIME18.;

cards;
 1000.700   571.900   573.600   368.300   146.600   114.800   122.300
  389.100   571.200   647.600   754.300  1030.200   733.800   541.400
;
run;
proc print data=exp1;
run;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章