BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sanketshah07
Obsidian | Level 7

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?

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
if upcase(ampm) = 'AM' then time=hms(hours,minutes,0);
else if upcase(ampm) = 'PM' then time=hms(hours+12,minutes,0);
--
Paige Miller

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26
if upcase(ampm) = 'AM' then time=hms(hours,minutes,0);
else if upcase(ampm) = 'PM' then time=hms(hours+12,minutes,0);
--
Paige Miller
sanketshah07
Obsidian | Level 7

What do I use to format the time back to HH:MM?

PaigeMiller
Diamond | Level 26

You can use the HHMM. format

--
Paige Miller
sanketshah07
Obsidian | Level 7
Thanks so much 🙂
singhsahab
Lapis Lazuli | Level 10


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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1924 views
  • 2 likes
  • 3 in conversation