DATA Step, Macro, Functions and more

Hour minutes informat

Accepted Solution Solved
Reply
Contributor
Posts: 71
Accepted Solution

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
4 weeks ago
Super User
Posts: 6,946

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

View solution in original post


All Replies
Solution
4 weeks ago
Super User
Posts: 6,946

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
Contributor
Posts: 71

Re: Hour minutes informat

Thanks KurtBremser, it works.

 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 121 views
  • 0 likes
  • 2 in conversation