SAS中文论坛

标题: how to calculate time in and time out question [打印本页]

作者: shiyiming    时间: 2009-10-28 10:41
标题: how to calculate time in and time out question
Hi all,

do any know how to calculate time in and time out question.
I would like to know how long abc and def
are using computer in rooms.

NetId  Logindata      room        time
abc        IN           KKK250H   46200
abc       OUT         KKK250H   48061
def         IN           RRR150A    43140
def        OUT         RRR150A   43148

thanks for helping. (^^)
作者: shiyiming    时间: 2009-10-28 16:52
标题: Re: how to calculate time in and time out question
我觉得可以先把In提取出来进一个file: timein,这里面把time改成timein;然后把out提取出来进另一个file: timeout,把这里的time改成timeout。
最后merge timein timeout,这样你就可以用timeout-timein得出duration了。
作者: shiyiming    时间: 2009-10-29 09:25
标题: Re: how to calculate time in and time out question
what if you have the missing value in logindata, such as abc is missing Login out information

NetId Logindata room time
abc IN KKK250H 46200
abc IN KKK243s  48756
abc OUT KKK250H 48061

Thanks a lot.
New SAS learner
作者: shiyiming    时间: 2009-10-29 09:43
标题: Re: how to calculate time in and time out question
[code:1qdgo50v]data raw;
        input NetId $ Logindata $ room $ time;
        format time time8.;
datalines;
abc IN KKK250H 46200
abc IN KKK243s 48756
abc OUT KKK250H 48061
;

proc sort data=raw;
        by netid room;
run;

data temp(drop=logindata time);
        do _n_=1 by 1 until(last.room);
                set raw;
                by netid room;
                if upcase(logindata)='IN' then in_time=time;
                else if upcase(logindata)='OUT' then out_time=time;
        end;
        dif_time=out_time-in_time;
        format dif_time in_time out_time time8.;
run;[/code:1qdgo50v]
作者: shiyiming    时间: 2009-10-30 07:12
标题: Re: how to calculate time in and time out question
Hi hopewell dengzi
thanks for your advise that giving me more understandable in SAS

Thanks again




欢迎光临 SAS中文论坛 (https://mysas.net/forum/) Powered by Discuz! X3.2