我试图将上午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;发布于 2014-02-27 16:27:27
Interval=ceil(minute+(ht-9)*60)-30)/15);
发布于 2014-02-27 16:49:41
更多的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以最简单的形式接受三个参数:间隔的类型、开始时间和结束时间,并告诉您从起始时间到结束时间跨越了间隔边界多少次。这种间隔是一种时间单位(“分钟”、“月”、“小时”等)和一对数字的组合,如果需要的话,用小数点分隔;左手是间隔的数字,右手是移位(所以如果你想在5分钟内开始你的15分钟间隔,它就是MINUTE15.5)。
https://stackoverflow.com/questions/22073732
复制相似问题