转换为SAS时间

转换为SAS时间,sas,Sas,我有一个包含时间的txt文件,格式为161058.262,预期为16:10:58.262 我找不到将此值转换为正确SAS数字时间值的信息。TIME12.3将转换为数字。它存储为579824520,并使用22:22:00.000格式的TOD12.3格式显示 有什么建议吗 谢谢 Dan我不知道具体的信息,但你当然可以用冒号,或者用HMS计算时间 data test; informat t_pre $10.; input t_pre $; t = input(catx(':',substr(t_pre

我有一个包含时间的txt文件,格式为161058.262,预期为16:10:58.262

我找不到将此值转换为正确SAS数字时间值的信息。TIME12.3将转换为数字。它存储为579824520,并使用22:22:00.000格式的TOD12.3格式显示

有什么建议吗

谢谢
Dan

我不知道具体的信息,但你当然可以用冒号,或者用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;

我会进行快速转换,使现有的informat正常工作。例如,您的格式与
B8601TM
所期望的格式相同,除了分隔一秒分数的点。您可以从字符串中去掉圆点,然后应用信息

例如:

data test;
    input t $10.;

    format tt TOD12.3;

    tt = inputn(compress(t, , "kn"),  "B8601TM9.3");

datalines;
161058.262
; run;
代码 日志
请详细说明一点,但更多的问题,并可能张贴您的文件的一部分,什么背景和语言,你在使用它等。。。您可以将文件导入MS Excel并在其中处理时间,或者编写一个AutoIt脚本来修复日期格式…似乎他正在使用SAS,因为他标记了这个SAS?
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