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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.