Hello,
I have hours, minutes and am/pm as three seperate columns. I need to concatenate these to form one HH:MM variable, preferable 24 hour clock, so that I can gt and lt functions with the time. Any advice?
if upcase(ampm) = 'AM' then time=hms(hours,minutes,0);
else if upcase(ampm) = 'PM' then time=hms(hours+12,minutes,0);
if upcase(ampm) = 'AM' then time=hms(hours,minutes,0);
else if upcase(ampm) = 'PM' then time=hms(hours+12,minutes,0);
What do I use to format the time back to HH:MM?
You can use the HHMM. format
proc sql;
create table want as
select hh,mm,ampm , case when ampm='am' then hms(hh,mm,0) else hms(hh+12,mm,0) end as time format=hhmm. from have;
quit;
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 lock in 2025 pricing—just $495!
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.