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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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