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

Good afternoon. I'd be thankful for any help you might provide to me.

 

I have a date/time variable with 24-hour time as part of that. What I need to do is to not only strip out the time but to convert it to a simple number. So from 021318 14:30:00 I just need 143000. I can split out the date but each time I try to do the same with the time portion I get 14:30:00 (with special characters). I'd like them to be gone but I can't figure out a good way to do that.

 

Thank you very much.

 

 

 

start_time want
021318 14:30:00 143000
021318 13:10:00 131000
021318 13:30:00 133000
021318 13:37:00 133700
021318 15:30:00 153000
021318 15:30:00 153000
021318 18:30:00 183000
021318 19:00:00 190000
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

One way to get what I think you are asking for

want= input(compress(put(timepart(start_time),time8.),':'),F6.);

or

want = hour(start_time)*10000+minute(start_time)*100+second(start_time));

 

I do kind of wonder in what way that format is more useful though.

View solution in original post

3 REPLIES 3
ballardw
Super User

One way to get what I think you are asking for

want= input(compress(put(timepart(start_time),time8.),':'),F6.);

or

want = hour(start_time)*10000+minute(start_time)*100+second(start_time));

 

I do kind of wonder in what way that format is more useful though.

Reeza
Super User
Use the TIMEPART() function to extract the time. Then you can apply a format to it. Time values are stored as the number of seconds so you could format it various manners or convert it to an actual number. Note that if you keep it as a time and want to calculate duration thats possible but not if you convert it to a number.
Jeff_DOC
Pyrite | Level 9

Thank you very much. I'm sure there may be other suggestions here that might work as well but this one was so easy even I could make it work!

 

Thank you.

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 3 replies
  • 2740 views
  • 0 likes
  • 3 in conversation