我有一个包含时间的txt文件,格式为161058.262,目的是16:10:58.262。
我找不到将此值转换为正确的SAS数字时间值的INFORMAT。 TIME12.3将转换为数字。它存储为579824520,并使用格式TOD12.3格式显示为22:22:00.000
有什么建议吗?
由于 丹
答案 0 :(得分:5)
我会做一个快速转型,使现有的信息工作。例如,您的格式与B8601TM
期望的格式相同,除了分隔秒的小数点的点。您可以从字符串中删除点,然后应用信息。
示例:
data test;
input t $10.;
format tt TOD12.3;
tt = inputn(compress(t, , "kn"), "B8601TM9.3");
datalines;
161058.262
; run;
答案 1 :(得分:1)
我不知道具体的信息,但你当然可以在冒号工作,或者做数学计算以使其成为使用HMS的时间。
data test;
informat t_pre $10.;
input t_pre $;
t = input(catx(':',substr(t_pre,1,2),substr(t_pre,3,2),substr(t_pre,5)),TIME12.3);
*CATX concatenates using a delimiter, so this generates a string like 16:10:58.262;
*Then converts to TIME12.3;
put t= TIME12.3 t_pre=;
datalines;
161058.262
;;;;
run;
data test;
input t_pre;
t = hms(floor(t_pre/10000),floor(mod(t_pre,10000)/100),mod(t_pre,100));
*HMS generates a time value from hours, minutes, seconds, and allows milliseconds in the seconds;
*So we use combination of division and modulo to separate the number into component parts;
put t= TIME12.3;
datalines;
161058.262
;;;;
run;
答案 2 :(得分:1)
data _null_;
input int_val $10.;
format time_val timeampm15.3;
time_val = input(
prxchange('s/(\d?\d)(\d\d)(\d\d\.\d\d\d)/$1:$2:$3/',
-1, int_val),
time10.3);
put int_val
@15 time_val timeampm15.3
@30 time_val 10.3;
datalines;
000000.001
012345.678
12345.678
161058.262
235959.999
run;
000000.001 12:00:00.000 AM 0.000
012345.678 1:23:45.600 AM 5025.600
12345.678 1:23:45.670 AM 5025.670
161058.262 4:10:58.200 PM 58258.200
235959.999 11:59:59.900 PM 86399.900
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds