标题: sas 陣列求教 [打印本页] 作者: shiyiming 时间: 2009-8-11 21:36 标题: sas 陣列求教 各位大大 ,小弟有个阵列上的问题,烦请协助
问题如下:
班车 总时间(分钟) 上车时间 下车时间
A1 50 7:30 8:20 上车时间7:30 +50分钟後為下车时间 8:20
A2 80 8:20 9:40
A3 100 9:40 11:20
请问SAS如何写该程式
谢谢作者: shiyiming 时间: 2009-8-11 21:43 标题: Re: sas 陣列求教 不好意思,以上问题,只有班车,总时间,及第一班上车时间为已知7:30
其它都是要用程式计算出来的结果作者: shiyiming 时间: 2009-8-11 22:47 标题: Re: sas 陣列求教 data t;
input bus $2. t_time 4. b_time time8.;
e_time=intnx('minute',b_time,t_time);
format b_time e_time time8.;
cards;
A1 50 7:30
A2 80 8:20
A3 100 9:40
;
proc print;
run;作者: shiyiming 时间: 2009-8-12 01:03 标题: Re: sas 陣列求教 If my understanding is correct, let's suppose your initial dataset (Dat_1)
looks like:
Bus Tot T1
A1 50 07:00
A2 60 .
A3 50 .
A4 80 .
A5 70 .
The t1 must be save in time format (e.g. '07:00't).
data dat_2;
set dat_1;
retain t2 0;
if _N_=1 then t2=t1+tot*60;
else
do;
t1=t2; t2=t1+tot*60;
end;
format t1 t2 time.;
run;作者: shiyiming 时间: 2009-8-12 08:02 标题: Re: sas 陣列求教 谢谢您了,
但如果要加上日期呢?如8/8/23:50
总时间为50分钟,
让其下车时间为8/9/00:40分呢?????作者: shiyiming 时间: 2009-8-12 21:30 标题: Re: sas 陣列求教 when you create initial dataset, you should use t1='12AUG2009:07:30'dt.
Then change t1, t2 format into datetime (e.g. format t1 t2 datetime.<!-- s;) --><img src="{SMILIES_PATH}/icon_wink.gif" alt=";)" title="Wink" /><!-- s;) --> .
The datetime format you described (e.g. 8/8/23:50) is not a SAS datetime format.
If you have to use your format, please use functions of day(), month(), and time()
to pick up the information you need and then make them as strings, finally combine
them to create a string looks like your format.作者: shiyiming 时间: 2009-8-12 23:02 标题: Re: sas 陣列求教 了解,非常感谢您的帮助