楼主: lovelybetty1208
8274 7

如何计算2个时间变量的差 [推广有奖]

  • 0关注
  • 1粉丝

已卖:1份资源

博士生

47%

还不是VIP/贵宾

-

威望
0
论坛币
97 个
通用积分
0
学术水平
1 点
热心指数
5 点
信用等级
1 点
经验
17470 点
帖子
293
精华
0
在线时间
147 小时
注册时间
2011-11-5
最后登录
2015-7-11

楼主
lovelybetty1208 发表于 2013-4-4 21:00:22 |AI写论文
2论坛币
现有数据集中有2个时间字段,都是精确到秒的,第一个是事件发生时间,第二个是结束事件,求中间间隔时间,结果显示为多少分多少秒。
具体数据集如下:
data aaaa;
input serv_id $ otherpart $ comm_type $ start_time datetime19.  end_time datetime19. ;
informat
serv_id $2.
otherpart $2.
comm_type $2.
start_time datetime19.
end_time   datetime19.;

format
serv_id $2.
otherpart $2.
comm_type $2.
start_time datetime19.
end_time   datetime19.;

cards;
a b 1 10NOV2012:03:40:19 10NOV2012:03:59:19
a c 1 10NOV2012:04:40:19 10NOV2012:05:15:19
a b 0 22NOV2012:16:22:11 22NOV2012:16:22:11                                
b a 1 02NOV2012:09:49:13 02NOV2012:09:59:19
c b 1 02NOV2012:13:00:19 02NOV2012:13:12:19
d l 0 26NOV2012:23:49:19 27NOV2012:01:59:19
;
run;


最佳答案

webgu 查看完整内容

data aaaa; input serv_id $ otherpart $ comm_type $ start_time datetime19. end_time datetime19. ; informat serv_id $2. otherpart $2. comm_type $2. start_time datetime19. end_time datetime19.; format serv_id $2. otherpart $2. comm_type $2. start_time datetime19. end_time datetime19.; diff= put(int((end_time-start_time)/60), best.) ||"Minutes"||","||put(mod(end_time-start_tim ...
关键词:时间变量 datetime informat informa format 计算 时间 如何
耶和华是我的牧者,我必不致缺乏。
他使我躺卧在青草地上,
领我在可安歇的水边。

沙发
webgu 发表于 2013-4-4 21:00:23
data aaaa;
input serv_id $ otherpart $ comm_type $ start_time datetime19.  end_time datetime19. ;
informat
serv_id $2.
otherpart $2.
comm_type $2.
start_time datetime19.
end_time   datetime19.;

format
serv_id $2.
otherpart $2.
comm_type $2.
start_time datetime19.
end_time   datetime19.;

diff= put(int((end_time-start_time)/60), best.) ||"Minutes"||","||put(mod(end_time-start_time,60), best.)||"seconds";

cards;
a b 1 10NOV2012:03:40:19 10NOV2012:03:59:19
a c 1 10NOV2012:04:40:19 10NOV2012:05:15:19
a b 0 22NOV2012:16:22:11 22NOV2012:16:22:11                                
b a 1 02NOV2012:09:49:13 02NOV2012:09:59:19
c b 1 02NOV2012:13:00:19 02NOV2012:13:12:19
d l 0 26NOV2012:23:49:19 27NOV2012:01:59:19
;
run;
SAS资源
1. SAS 微信:StatsThinking
2. SAS QQ群:348941365

藤椅
hzguba 发表于 2013-4-4 21:07:16
楼主牛啊

板凳
zhengbo8 发表于 2013-4-4 21:09:25
  1. data b;
  2.     set aaaa;
  3.     dif=cat(minute(intck('second',start_time,end_time)),'分',second(intck('second',start_time,end_time)),'秒');
  4. run;
复制代码

2013-04-04_211556.gif
2013-04-04_211556.gif
已有 1 人评分学术水平 热心指数 收起 理由
lovelybetty1208 + 1 + 1 热心帮助其他会员

总评分: 学术水平 + 1  热心指数 + 1   查看全部评分

报纸
lovelybetty1208 发表于 2013-4-4 21:21:31
zhengbo8 发表于 2013-4-4 21:09
感谢你的帮助,有2个问题请教你
1.如果我要精确到 几分钟零几秒钟  要怎么改呢?
2.如何在回复时吧自己的代码设置成像你这样的。我希望在自己力所能及的时候也能帮别人。呵呵。
耶和华是我的牧者,我必不致缺乏。
他使我躺卧在青草地上,
领我在可安歇的水边。

地板
zhengbo8 发表于 2013-4-4 21:26:56
lovelybetty1208 发表于 2013-4-4 21:21
感谢你的帮助,有2个问题请教你
1.如果我要精确到 几分钟零几秒钟  要怎么改呢?
2.如何在回复时吧自己 ...
2013-04-04_211556.gif

2013-04-04_212004.gif
注意红色部分!

已有 1 人评分学术水平 热心指数 信用等级 收起 理由
lovelybetty1208 + 1 + 1 + 1 补偿

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

7
lovelybetty1208 发表于 2013-4-4 21:52:25
zhengbo8 发表于 2013-4-4 21:26
注意红色部分!
因为另一位朋友完整地回答了我的问题,所以奖励给他了。不过我给你的回复评分作为补偿了。再次感谢你!
耶和华是我的牧者,我必不致缺乏。
他使我躺卧在青草地上,
领我在可安歇的水边。

8
zhengbo8 发表于 2013-4-4 21:54:46
回答问题也是在学习知识。呵呵~

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-20 07:35