簡體   English   中英

如何在SAS中更有效地將日內時段分為15分鍾的組?

[英]How can I group intra-day time periods into groups of 15 minutes in SAS more efficiently?

我正在嘗試將上午9:30-下午4:00的交易時間划分為15分鍾間隔。 我想分別對每個15分鍾間隔進行一次分析。 我如何簡化下面的代碼,而不是在26天的15分鍾間隔內重復執行if語句?

我需要有一個名為interval的變量,如下所示,因為這樣我可以選擇僅對某些間隔(例如“ if interval <3”)運行分析。

謝謝。

int=(minute+(hour-9)*60)-29;
if int<16 then interval=1;
if int=>16 and int< 31 then interval=2;
if int=>31 and int< 46 then interval=3;
if int=>46 and int< 61 then interval=4;

一種更SASsy的方法是使用INTCK

*Create test dataset;
data have;
format trade_time TIME9.;
do trade_time = '09:00:00't to '16:00:00't by 480;
  output;
end;
run;

data want;
set have;
interval = intck('MINUTE15','09:00:00't,trade_time)+1;
run;

這在數學上比較簡單,並且更靈活,因為它可以輕松計算任何類型的間隔。

intck以最簡單的形式接受三個參數:間隔的類型,開始時間和結束時間,並告訴您越過間隔邊界多少次才能從開始時間到達該結束時間。 時間間隔的類型是時間單位(“ MINUTE”,“ MONTH”,“ HOUR”,諸如此類)和一對數字(如果需要的話)之間的組合; 左手是間隔號,右手是班次(因此,如果您想在5分鍾標記處開始15分鍾間隔,則應為MINUTE15.5 )。

interval = ceil((((minute +(hour-9)* 60)-30)/ 15);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM