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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Howles
Quartz | Level 8

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

format time time5. ;

View solution in original post

4 REPLIES 4
CTorres
Quartz | Level 8

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

Howles
Quartz | Level 8

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

format time time5. ;

bharathtuppad
Obsidian | Level 7

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;

koushik
Calcite | Level 5

hi all,

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

koushik

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 9210 views
  • 8 likes
  • 4 in conversation