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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.