DATA Step, Macro, Functions and more

Need help in time format

Reply
Occasional Contributor
Posts: 9

Need help in time format

Hi all,

 

I have time format 515 and i want desired time format as 05:15.

could anybody help me with getting the desired format.

PROC Star
Posts: 1,215

Re: Need help in time format

Posted in reply to apxprdtr10

Is time a character or numeric variable?

 

Either way, do something like this

 

data have;
   Time=515;
   CharTime=put(Time, 4.);
   RightTime=input(put(Time, 4.), hhmmss5.);
   format RightTime time5.;
run;
Super User
Posts: 13,321

Re: Need help in time format

Posted in reply to apxprdtr10

Assuming your existing variable is actually numeric here is an example:

data junk;
   x=515;
   x=input(put(x,z4.),hhmmss.);
   format x time5.;
run;
Occasional Contributor
Posts: 9

Re: Need help in time format

I really appreciate your valuable reply but it just slightly differ from my desired result.

your replied answer gives me time as 5:15 but i want as 05:15

PROC Star
Posts: 8,149

Re: Need help in time format

Posted in reply to apxprdtr10

You could always just roll your own format. e.g.:

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

data junk;
   x=515;
   x=input(put(x,z4.),hhmmss.);
   format x todx.;
run;

Art, CEO, AnalystFinder.com

 

Ask a Question
Discussion stats
  • 4 replies
  • 80 views
  • 1 like
  • 4 in conversation