AM/PM to military time

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 13
Accepted Solution

AM/PM to military time

Hi,

 

I am trying to convert AM/PM into military time. I've looked through past inquiries into this and the code is not working for me. As a couple of examples, the times are 7:00 AM and 5:55 AM. They are currently stored as character variables and the format that they are currently in is $9. Here's the code that I've been trying to get working:

 

data psqi3;
set psqi;
up_time=input(up_time, TIME8.);
format up_time time8.;
run;

 

1065
1066 data psqi3;
1067 set psqi;
1068 up_time=input(up_time, TIME8.);
1069 format up_time time8.;
                                   ------
48
ERROR 48-59: The format $TIME was not found or could not be loaded.

1070 run;

 

Does anyone have any thoughts on what I'm doing wrong here?

 

Thanks!


Accepted Solutions
Solution
‎12-09-2016 02:18 AM
Super User
Posts: 17,868

Re: AM/PM to military time

You can't use the same variable Name, you need to create a new variable to hold the numeric value of time. 

Otherwise it should work. 

 

This is because you can't change a variable type in SAS. 

View solution in original post


All Replies
Solution
‎12-09-2016 02:18 AM
Super User
Posts: 17,868

Re: AM/PM to military time

You can't use the same variable Name, you need to create a new variable to hold the numeric value of time. 

Otherwise it should work. 

 

This is because you can't change a variable type in SAS. 

Trusted Advisor
Posts: 1,395

Re: AM/PM to military time

You input is defined as $9 then try up_time=input(up_time, TIME9.);

 

I have run next code as test :

     data _NULL_;

         length tmx $9;

         tmx = '7:30 PM';

         tm = input(tmx, time9.);

         put tm time5.;

   run;

   log showed: 19:30

Trusted Advisor
Posts: 1,395

Re: AM/PM to military time

@Reeza is right.

The cause to error is not the length.

Occasional Contributor
Posts: 13

Re: AM/PM to military time

Right. Fixing that silly error fixed it. Thanks.
☑ This topic is SOLVED.

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

Discussion stats
  • 4 replies
  • 371 views
  • 2 likes
  • 3 in conversation