BookmarkSubscribeRSS Feed
0 Likes

At the moment, this

data T;
  A1='2:30:00 pm';
  A2=input(A1,time11.);
  A3=input(A1,anydttme11.);
  B1='2:30:0 p.m.';
  B2=input(B1,time11.);
  B3=input(B1,anydttme11.);
run;

yields

A1 A2 A3 B1 B2 B3
2:30:00 pm 52200 52200 2:30:0 p.m. . .

 

4 Comments
ballardw
Super User

Interesting. Playing a bit with the code:

data T;
A1='2:30:00 pm';
A2=input(A1,time11.);
A3=input(A1,anydttme12.);
B1='2:30:0 p.m.';
B2=input(B1,time11.);
B3=input(B1,anydttme12.);
format a2 a3 b2 b3 timeampm11.;
run;

I get

          A1                 A2             A3        B1                  B2             B3

      2:30:00 pm     2:30:00 PM     2:30:00 PM    2:30:0 p.m.     2:30:00 PM     2:30:00 PM

ChrisNZ
Tourmaline | Level 20

I see.

Your code makes no difference to me.

I'm using version 9.4 M2.

Why use a length of 12 ?

ballardw
Super User

I'm on 9.4 M4 which seems to be the actual difference. The first time I ran the code I just used the default anydtdtm width just to see which truncates with a default 8 character, and then tried 12 width to account for potential 2-digit hours and that "worked" for me. Stopped too soon. It also works with 11 as a later trial.

 

I've seen that sometimes that the ANYDT informats need a wider definition than the number of characters/digits actually present. I don't remember the exact case but it involved a datetime value that read the correct value when the Anydtdte used a width of 32 which was several characters wider than the test value. That was arrived at by adding one to the width until finding a width that worked with the particular layout.

ChrisNZ
Tourmaline | Level 20

It seems this is a bug that has since been fixed then. I can't delete the suggestion.

Interesting that the ANYDT informats exhibit quirky length requirements, I'll remember that. Just like the datetime format. I wonder what's happening behind the scene.