Hi Team,
How shall I convert below mentioned data into 24 hours format of hh:mm:ss (char).
data want ;
time="04:56 PM";output;
time="11:59 PM";output;
time="12:00 PM";output;
time="12:51 PM";output;
time="00:00 AM";output;
time="10:19 AM";output;
time="01:19 AM";output;
run;
Thank you in advance.
Use the TIME informat to convert those strings to actual time values (number of seconds) and then use the TOD format to convert it back to a string.
data have ;
input time $8. ;
cards;
04:56 PM
11:59 PM
12:00 PM
12:51 PM
00:00 AM
10:19 AM
01:19 AM
;
data want;
set have;
time2=put(input(time,time8.),tod8.);
run;
proc print;
run;
Obs time time2 1 04:56 PM 16:56:00 2 11:59 PM 23:59:00 3 12:00 PM 12:00:00 4 12:51 PM 12:51:00 5 00:00 AM 00:00:00 6 10:19 AM 10:19:00 7 01:19 AM 01:19:00
But it might be easier to deal with the values if you left them as numeric time values instead of strings.
time2=input(time,time8.) ;
format time2 tod8. ;
Use the TIME informat to convert those strings to actual time values (number of seconds) and then use the TOD format to convert it back to a string.
data have ;
input time $8. ;
cards;
04:56 PM
11:59 PM
12:00 PM
12:51 PM
00:00 AM
10:19 AM
01:19 AM
;
data want;
set have;
time2=put(input(time,time8.),tod8.);
run;
proc print;
run;
Obs time time2 1 04:56 PM 16:56:00 2 11:59 PM 23:59:00 3 12:00 PM 12:00:00 4 12:51 PM 12:51:00 5 00:00 AM 00:00:00 6 10:19 AM 10:19:00 7 01:19 AM 01:19:00
But it might be easier to deal with the values if you left them as numeric time values instead of strings.
time2=input(time,time8.) ;
format time2 tod8. ;
data want ; time="04:56 PM"t;output; time="11:59 PM"t;output; time="12:00 PM"t;output; time="12:51 PM"t;output; time="00:00 AM"t;output; time="10:19 AM"t;output; time="01:19 AM"t;output; format time tod.; run;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.