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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 8484 views
  • 8 likes
  • 4 in conversation