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.
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;
According to which standard (reference) ?
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.
time = hms(input(substr(mTime,1,2), best.), input(substr(mTime,3,2), best.), 0);
Is the solution for SAS?
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 |
Show us the code you used and the results. Explain what was wrong with the answers.
Repeating: "Show us the code you used"
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)
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;
@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?
SAS is headed back to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team.
Interested in speaking? Content from our attendees is one of the reasons that makes SAS Innovate such a special event!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.