Hello everyone,
I am working with a string variable that has cpu time. I am trying to aggregate them together but I can't convert the string to time format or sum them together. Can anyone offer a clue?
data sas;
input timeval $ ;
datalines;
01:24.3
02:57.4
02:41.0
03:25.7
01:17.0
04:06.0
03:44.1
02:54.0
03:04.3
03:07.9
01:20.0
04:10.5
03:40.7
03:20.4
02:16.4
02:31.6
01:54.0
01:47.9
03:48.8
10:38.2
01:00.2
01:03.5
01:03.8
01:11.1
01:00.1
01:13.9
01:01.8
03:13.8
06:37.6
07:29.9
03:52.7
01:03.6
01:30.7
01:34.9
02:08.1
01:00.4
01:02.8
01:00.7
01:00.2
01:05.0
01:01.0
01:01.8
01:07.8
01:06.6
01:06.8
01:13.6
01:01.1
01:01.7
01:04.3
01:00.0
01:01.9
01:01.3
01:01.3
01:01.3
01:01.4
01:02.8
02:16.4
02:26.9
01:02.8
01:31.8
01:52.2
01:50.5
01:58.6
01:45.5
01:58.6
01:35.5
01:56.5
01:58.7
01:30.8
01:35.9
01:49.1
01:56.2
01:31.9
01:56.4
01:56.3
01:31.6
01:39.2
01:45.1
01:59.1
01:49.6
01:36.9
01:58.4
01:59.9
01:53.2
01:42.7
02:00.0
01:57.1
01:48.5
01:44.5
01:56.5
01:56.0
01:40.0
01:45.7
01:55.9
01:55.3
01:48.0
01:56.8
01:00.0
01:00.4
01:00.1
01:00.2
01:00.1
01:00.1
01:00.0
01:09.6
01:00.5
01:00.5
01:00.5
01:00.8
01:00.1
01:01.2
01:02.6
01:00.3
01:00.4
01:00.3
01:00.2
01:00.1
01:00.2
01:00.5
01:00.3
01:00.2
01:00.2
01:00.0
01:00.7
01:00.8
01:00.2
01:00.5
01:00.5
01:00.5
01:00.4
01:00.6
01:00.5
01:00.7
01:00.6
01:00.4
01:00.3
01:02.2
01:00.4
01:00.6
01:00.4
01:00.6
01:00.9
01:00.6
01:00.2
01:00.7
01:00.8
01:00.3
01:00.4
01:00.5
01:00.6
01:00.4
01:00.5
01:00.3
01:24.5
01:19.5
01:01.3
01:07.5
01:17.3
01:20.8
01:29.8
01:25.8
01:21.0
01:20.4
01:17.9
01:17.7
01:23.2
01:07.4
01:24.3
01:20.4
01:19.9
01:16.5
01:23.7
01:23.7
01:24.3
01:20.1
01:25.1
01:23.3
01:22.4
01:18.7
01:24.9
01:26.0
01:18.3
01:03.9
01:22.9
01:20.3
01:33.0
01:17.9
01:23.8
01:18.4
01:23.8
01:13.5
01:24.8
01:20.1
01:24.1
01:20.0
01:25.9
01:20.5
01:22.0
01:26.6
01:21.3
01:05.2
01:27.3
01:13.5
01:26.1
01:27.0
01:26.7
01:24.2
01:25.4
01:25.9
01:25.8
01:26.0
01:26.7
01:25.4
01:26.4
01:24.2
01:20.7
01:25.8
01:26.3
01:26.4
01:29.1
01:26.4
01:27.1
01:26.0
01:26.5
;
run;
data rest;
set sas;
a_timeval=input(timeval, mmss.);
run;
data want;
input timeval $10.;
time=input(cats('00:',timeval),time10.1);
format time time10.1;
datalines;
...
;
You should be able to sum these.
proc summary data=have;
var time;
output out=want sum=sum_time;
run;
data want;
input timeval $10.;
time=input(cats('00:',timeval),time10.1);
format time time10.1;
datalines;
...
;
You should be able to sum these.
proc summary data=have;
var time;
output out=want sum=sum_time;
run;
Thank you. That worked.
Hi @yo1 If you just want minutes and seconds , just use time5. informat
data rest;
set sas;
a_timeval=input(timeval, time5.);
format a_timeval time5.;
run;
Oh sorry my bad. Well I am pleased you have a working solution.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.