BookmarkSubscribeRSS Feed
quanzhou22
Calcite | Level 5

Can anyone help me to figure out the code that can change a time variable in SAS from HH : MM : SS.SS to HHMM?

like 20:35:00.00 to 2035

Thanks very much!

3 REPLIES 3
Reeza
Super User

I don't think there's a format, but you can easily create your own using proc format.

 

proc format;
  picture mytime other='%0H%0M' (datatype=time);
run;

 

quanzhou22
Calcite | Level 5

Thanks for your answer. 

I figured it out just now and it works for my assignment.

Here is the code:

 

data time;
set Slice;
OrderTimeNewPart1=substrn(OrderTime,1,2);
OrderTimeNewPart2=substrn(OrderTime,4,2);
OrderTimeNewPart=trim(OrderTimeNewPart1)||OrderTimeNewPart2;
OrderTimeNew=prxchange('s/^0+//o',-1,OrderTimeNewPart);
drop OrderTimeNewPart1 OrderTimeNewPart2 OrderTimeNewPart;
run;

Reeza
Super User

Your variable is now text. Depending on what you want that may be fine, but in general I find it easier to keep them as date/time/datetime for analysis and calculations later on. 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 741 views
  • 1 like
  • 2 in conversation