SAS Programming

DATA Step, Macro, Functions and more
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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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