- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Reeza is right.
The cause to error is not the length.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content