## Hour minutes informat

Solved
Frequent Contributor
Posts: 112

# Hour minutes informat

SAS gurus,
How can I read time (0233 or 1433) in sas?
HHMM. Is not working and I would like to see 24hrminute format
Have 0233 This is am
0233 This is pm

Want 0233
1433

Accepted Solutions
Solution
‎07-26-2017 06:39 AM
Super User
Posts: 10,280

## Re: Hour minutes informat

Adapt the number so that it fits the time. informat, and use the index() function to determine pm and am. Set the hour either by adding 12*360, or use the intnx() function:

``````data want;
input timestr \$25.;
time_num = input(substr(timestr,1,2) !! ':' !! substr(timestr,3,2),time5.);
if index(timestr,'pm') > 0 then time_num = intnx('hour',time_num,12,'s');
format time_num time8.;
cards;
0233 This is am
0233 This is pm
;
run;``````
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

All Replies
Solution
‎07-26-2017 06:39 AM
Super User
Posts: 10,280

## Re: Hour minutes informat

Adapt the number so that it fits the time. informat, and use the index() function to determine pm and am. Set the hour either by adding 12*360, or use the intnx() function:

``````data want;
input timestr \$25.;
time_num = input(substr(timestr,1,2) !! ':' !! substr(timestr,3,2),time5.);
if index(timestr,'pm') > 0 then time_num = intnx('hour',time_num,12,'s');
format time_num time8.;
cards;
0233 This is am
0233 This is pm
;
run;``````
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Frequent Contributor
Posts: 112

## Re: Hour minutes informat

Thanks KurtBremser, it works.

☑ This topic is solved.