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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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