Calcite | Level 5

## Military Time

I have an excel sheet where the data set has columns with military time but no separators. How to convert the military time to hh: mm. For example, the columns have military time like 1509,7,30,637.

1 ACCEPTED SOLUTION

Accepted Solutions
Opal | Level 21

## Re: Military Time

``````data have;
input COLLECTION_TIME \$ RECV_TIME \$;
datalines;
1509    613
2033    625
30  615
2130    603
2114    720
1009    639
1457    553
2131    634
627 550
1702    632
;

data want;
set have;
t = input(COLLECTION_TIME, best.);
COLLECTION_TIME_DT = hms(int(t/100), mod(t,100), 0);
t = input(RECV_TIME, best.);
RECV_TIME_DT = hms(int(t/100), mod(t,100), 0);
format COLLECTION_TIME_DT RECV_TIME_DT hhmm5.;
run;

proc print data=want; run;``````

PG
14 REPLIES 14
Opal | Level 21

## Re: Military Time

According to which standard (reference) ?

PG
Calcite | Level 5

## Re: Military Time

Military time is 24 hr time, but it is in 1507 format which is 03:07 PM, I want to convert all the values to HH MM format.

Opal | Level 21

## Re: Military Time

``time = hms(input(substr(mTime,1,2), best.), input(substr(mTime,3,2), best.), 0); ``
PG
Calcite | Level 5

## Re: Military Time

Is the solution for SAS?

Calcite | Level 5

## Re: Military Time

The given solution did not work but I can provide you with an example of the dataset.

 COLLECTION_TIME RECV_TIME 1509 613 2033 625 30 615 2130 603 2114 720 1009 639 1457 553 2131 634 627 550 1702 632
Diamond | Level 26

## Re: Military Time

Show us the code you used and the results. Explain what was wrong with the answers.

--
Paige Miller
Calcite | Level 5

## Re: Military Time

I tried the code but the values were all missing
Diamond | Level 26

## Re: Military Time

Repeating: "Show us the code you used"

--
Paige Miller
Calcite | Level 5

## Re: Military Time

time = hms(input(substr(mTime,1,2), best.), input(substr(mTime,3,2), best.), 0);
Diamond | Level 26

## Re: Military Time

If you didn't change the variable names from the code by @PGStats to the varaible names in your data set, then I would expect missing values.

Show us the whole data step. Also, if there are any WARNINGs in the log, show those to us as well. (or just show us the entire LOG from this data step including CODE, ERRORs, WARNINGs and NOTEs)

--
Paige Miller
Opal | Level 21

## Re: Military Time

``````data have;
input COLLECTION_TIME \$ RECV_TIME \$;
datalines;
1509    613
2033    625
30  615
2130    603
2114    720
1009    639
1457    553
2131    634
627 550
1702    632
;

data want;
set have;
t = input(COLLECTION_TIME, best.);
COLLECTION_TIME_DT = hms(int(t/100), mod(t,100), 0);
t = input(RECV_TIME, best.);
RECV_TIME_DT = hms(int(t/100), mod(t,100), 0);
format COLLECTION_TIME_DT RECV_TIME_DT hhmm5.;
run;

proc print data=want; run;``````

PG
Calcite | Level 5

## Re: Military Time

So how can we enter all the observations from the dataset under datalines if we have more than 3000 observations?
Super User

## Re: Military Time

@SriCh1 wrote:
So how can we enter all the observations from the dataset under datalines if we have more than 3000 observations?

Why would you want to do that if you already have the data in the dataset you imported from Excel?

Calcite | Level 5

## Re: Military Time

Thank you so much the code worked!
Discussion stats
• 14 replies
• 1197 views
• 0 likes
• 4 in conversation