BookmarkSubscribeRSS Feed
hussainkw97
Calcite | Level 5

I have a time variable and I want to round the observations to the nearest 30 min. 

so 2:15:00 for example would be 2:30 

5:05:00 would be 5:00:00

5:20:00 would be 5:30:00  and so on. I would appreciate any help. 

 

I'm using base SAS 9.4

1 REPLY 1
PeterClemmensen
Tourmaline | Level 20
data have;
t='5:05:00't;output;
t='5:20:00't;output;
format t time.;
run;

data want;
   set have;
   roundedtime=round(t,'00:30:00't);
   format roundedtime time.;
run;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 1 reply
  • 1716 views
  • 9 likes
  • 2 in conversation