Time 将数值变量转换为SAS时间变量

Time 将数值变量转换为SAS时间变量,time,format,sas,Time,Format,Sas,我导入了一个cvs文件,在sas文件中有一个由四位数字组成的变量“出发时间”,例如08.56 AM的0856。我希望SAS将其识别为时间,并希望其显示为08:56。我试过: put DEP_TIME hhmm5.; format DEP_TIME hhmm5.; 不起作用。我似乎无法理解这一点 有什么线索吗?我不认为有一个informat可以将一个4位数的字符串转换成时间 有几种方法可以做到这一点,可以使用hms()和substr()函数,也可以使用自定义图片格式: proc format

我导入了一个cvs文件,在sas文件中有一个由四位数字组成的变量“出发时间”,例如08.56 AM的
0856
。我希望SAS将其识别为时间,并希望其显示为
08:56
。我试过:

put DEP_TIME hhmm5.;

format DEP_TIME hhmm5.;
不起作用。我似乎无法理解这一点


有什么线索吗?

我不认为有一个informat可以将一个4位数的字符串转换成时间

有几种方法可以做到这一点,可以使用
hms()
substr()
函数,也可以使用自定义图片格式:

proc format ; picture TM low-high = '00:00' ; run ; data want ; set have ; /* hms and substr method */ new_time1 = hms(substr(dep_time,1,2),substr(dep_time,3,2)) ; format new_time1 hhmm5. ; /* input / put with picture format */ new_time2 = input(put(input(dep_time,4.),tm.),time5.) ; format new_time2 hhmm5. ; run ; proc格式; 图片商标 低-高='00:00'; 跑 数据需求; 集有; /*hms和substr方法*/ new_time1=hms(substr(dep_time,1,2),substr(dep_time,3,2)); 格式化新的\u时间1 hhmm5; /*使用图片格式输入/输出*/ 新的时间2=输入(输入(dep_-time,4.),tm.),时间5.); 格式化新的\u时间2 hhmm5; 跑
我不认为有一个informat可以将一个4位数的字符串转换成时间

有几种方法可以做到这一点,可以使用
hms()
substr()
函数,也可以使用自定义图片格式:

proc format ; picture TM low-high = '00:00' ; run ; data want ; set have ; /* hms and substr method */ new_time1 = hms(substr(dep_time,1,2),substr(dep_time,3,2)) ; format new_time1 hhmm5. ; /* input / put with picture format */ new_time2 = input(put(input(dep_time,4.),tm.),time5.) ; format new_time2 hhmm5. ; run ; proc格式; 图片商标 低-高='00:00'; 跑 数据需求; 集有; /*hms和substr方法*/ new_time1=hms(substr(dep_time,1,2),substr(dep_time,3,2)); 格式化新的\u时间1 hhmm5; /*使用图片格式输入/输出*/ 新的时间2=输入(输入(dep_-time,4.),tm.),时间5.); 格式化新的\u时间2 hhmm5; 跑 信息B8601TM

33         data _null_;
34            t='0856';
35            time = input(t,B8601TM.);
36            format time time.;
37            put 'NOTE: ' (_all_)(=);
38            run;

NOTE: t=0856 time=8:56:00
信息B8601TM

33         data _null_;
34            t='0856';
35            time = input(t,B8601TM.);
36            format time time.;
37            put 'NOTE: ' (_all_)(=);
38            run;

NOTE: t=0856 time=8:56:00

返回并在CSV导入中修复此问题-将信息和格式应用于变量。返回并在CSV导入中修复此问题-将信息和格式应用于变量。