DATA Step, Macro, Functions and more

converting numbers to time format?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 13
Accepted Solution

converting numbers to time format?

hello all,

in my question data set  i have a variable po_time as numbers and i want to create a new variable time in time format.

po_time       time

1253            12:53

116              13:16

143              12:43

238              14:38

there are lot of rows. i just want to convert to 24hr time format The variable po_time is in the numeric format.

please suggest. thanks in advance.

thanks.. Smiley Happy


Accepted Solutions
Solution
‎10-30-2014 06:08 PM
Regular Contributor
Posts: 184

Re: converting numbers to time format?

time = input(put(po_time,z4.),hhmmss4.) ;

format time time5. ;

View solution in original post


All Replies
Regular Contributor
Posts: 180

Re: converting numbers to time format?

Try this:

data have;
input po_time;
Cards;
1253      
116       
143       
238       
;
run;

data want (keep=po_time time);
  set have;
  h=int(po_time/100);
  m=po_time-(h*100);
  if h<12 then h=h+12;  /* Are you sure all times are in the afternoon?  */
  time=hms(h,m,0);
  format time time5.;
run;

CTorres

Solution
‎10-30-2014 06:08 PM
Regular Contributor
Posts: 184

Re: converting numbers to time format?

time = input(put(po_time,z4.),hhmmss4.) ;

format time time5. ;

Contributor
Posts: 27

Re: converting numbers to time format?

data have ;

input po_time ;

cards;

1253      

1160       

1430       

2380       

;

proc print;

run;

data want;

set have;

hms=hms(substr(left(po_time),1,2), substr(left(po_time), 3,2), 00);

format hms time8.;

run;

proc print;

run;

Occasional Contributor
Posts: 13

Re: converting numbers to time format?

Posted in reply to bharathtuppad

hi all,

thanks for your support.  all the answers are very helpful. gained knowledge. thanks for your time.  Smiley Happy

koushik

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 538 views
  • 6 likes
  • 4 in conversation