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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: