DATA Step, Macro, Functions and more

How do I create a time format from hhmmss formatted observations?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

How do I create a time format from hhmmss formatted observations?

Here is my code:

proc format ;
value militarytimeN
00:00:00 - 01:00:00 ="12am-1am"
01:00:00-02:00:00="1am-2am"
02:00:00-03:00:00="2am-3am"
03:00:00-04:00:00="3am-4am"
04:00:00-05:00:00="4am-5am"
05:00:00-06:00:00="5am-6am"
06:00:00-07:00:00="6am-7am"
07:00:00-08:00:00="7am-8am"
08:00:00-09:00:00="8am-9am"
09:00:00-10:00:00="9am-10am"
10:00:00-11:00:00="10am-11am"
11:00:00-12:00:00="11am-12pm"
12:00:00-13:00:00="12pm-1pm"
13:00:00-14:00:00="1pm-2pm"
14:00:00-15:00:00="2pm-3pm"
15:00:00-16:00:00="3pm-4pm"
16:00:00-17:00:00="4pm-5pm"
17:00:00-18:00:00="5pm-6pm"
18:00:00-19:00:00="6pm-7pm"
19:00:00-20:00:00="7pm-8pm"
20:00:00-21:00:00="8pm-9pm"
21:00:00-22:00:00="9pm-10pm"
22:00:00-23:00:00="10pm-11pm"
23:00:00-24:00:00="11pm-11:59pm";
run;

Here is my error message:

 

proc format ;

332 value militarytimeN

333 00:00:00 - 01:00:00 ="12am-1am"

- -

22 200

200

ERROR 22-322: Syntax error, expecting one of the following: (, ',', -, <, =.

ERROR 200-322: The symbol is not recognized and will be ignored.

333! 00:00:00 - 01:00:00 ="12am-1am"

-

22

ERROR 22-322: Syntax error, expecting one of the following: (, ',', =......

Accepted Solutions
Solution
a month ago
Community Manager
Posts: 2,956

Re: How do I create a time format from hhmmss formatted observations?

You have to express those time values with the literal format:

 

proc format ;
value militarytimeN
'00:00:00't - '01:00:00't ="12am-1am"
/* same for remaining values */
;
run;

But you might also want to explore what existing time formats and precision specifiers can do for you, perhaps saving the trouble of a new format.

View solution in original post


All Replies
Solution
a month ago
Community Manager
Posts: 2,956

Re: How do I create a time format from hhmmss formatted observations?

You have to express those time values with the literal format:

 

proc format ;
value militarytimeN
'00:00:00't - '01:00:00't ="12am-1am"
/* same for remaining values */
;
run;

But you might also want to explore what existing time formats and precision specifiers can do for you, perhaps saving the trouble of a new format.

☑ This topic is solved.

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

Discussion stats
  • 1 reply
  • 67 views
  • 0 likes
  • 2 in conversation