BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
chavens
Fluorite | Level 6

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

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

View solution in original post

4 REPLIES 4
Reeza
Super User

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. 

Shmuel
Garnet | Level 18

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

Shmuel
Garnet | Level 18

@Reeza is right.

The cause to error is not the length.

chavens
Fluorite | Level 6
Right. Fixing that silly error fixed it. Thanks.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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