DATA Step, Macro, Functions and more

A Quick question about SAS time from HH:MM:SS.SS to HHMM

Reply
New Contributor
Posts: 3

A Quick question about SAS time from HH:MM:SS.SS to HHMM

[ Edited ]

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!

Super User
Posts: 17,730

Re: A Quick question about SAS time from HH:MM:SS.SS to HHMM

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;

 

New Contributor
Posts: 3

Re: A Quick question about SAS time from HH:MM:SS.SS to HHMM

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;

Super User
Posts: 17,730

Re: A Quick question about SAS time from HH:MM:SS.SS to HHMM

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. 

Ask a Question
Discussion stats
  • 3 replies
  • 184 views
  • 1 like
  • 2 in conversation