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

HI!

 

I have numeric values in time variables using military time.  When I try the HHMM. the output is not correct

 

My data values look like this

Time
120
2130
10
1128
23
50

 

 

Want to look like this:

 

Time Want
120 01:20
2130 21:30
10 00:10
1128 11:28
23 00:23
50 00:50

 

 

Any suggestion appreciated!!

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Before you can use a time format, you have to convert the numbers to date-time numbers.

 

Something like this:

 

time2=hms(floor(time/100),mod(time,100),0); /* Convert time to hours and minutes using the hms function */
format time2 hhmm5.;

 

--
Paige Miller

View solution in original post

3 REPLIES 3
collinelliot
Barite | Level 11

Probably a slicker way, but this should work:

 

data have;
input have;
timepad =  strip(put(have, z4.));
want = hms(substr(timepad, 1, 2), substr(timepad, 3, 2), 0);
format want time5.;
datalines;
120
2130
10
1128
23
50
;
PaigeMiller
Diamond | Level 26

Before you can use a time format, you have to convert the numbers to date-time numbers.

 

Something like this:

 

time2=hms(floor(time/100),mod(time,100),0); /* Convert time to hours and minutes using the hms function */
format time2 hhmm5.;

 

--
Paige Miller
novinosrin
Tourmaline | Level 20

Mine isn't smart, but fun though-

 

data have;
input time;
datalines;
120
2130
10
1128
23
50
;
data want;
set have;
new_time=cats(reverse(substr(reverse(time),3)),':',substr(time,length(time)-1));
if length(new_time)=3 then new_time=cats('00',new_time);
run;

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
  • 3 replies
  • 1746 views
  • 4 likes
  • 4 in conversation