DATA Step, Macro, Functions and more

HHMMSS SAS ISSUE

Reply
Occasional Contributor
Posts: 8

HHMMSS SAS ISSUE

Experts,

I am trying to read in the below data using hhmmss informat. While using hhmmss informat, when there are less that 6 digits in the input, as per SAS user guide, it appends zeros to the end to make it 6 digits and reads it in.

But when 0010 as read in using hhmmss in SAS, it is read as 10 hours instead of 10 minutes (as I would expect.)

Is it a SAS bug? Anyone knows a work around to it. Thanks a lot for the help...

Test Program:

data _null_;

  x=input('0010',hhmmss.);

  y=input('123045',hhmmss.);

  put x=time8. y=time8.;

run;

SAS Log FIle:

1        !              

2          data _null_;

3            x=input('0010',hhmmss.);

4            y=input('123045',hhmmss.);

5            put x=time8. y=time8.;

6          run;

x=10:00:00 y=12:30:45

PROC Star
Posts: 1,167

Re: HHMMSS SAS ISSUE

Posted in reply to geoonline

I added these cases:

x2=input('0110',hhmmss.);

x3=input('1210',hhmmss.);

and they both worked correctly. I agree with you that your "x" example should be 00:10:00, not 10:00:00. I suspect that SAS is disregarding left digits of zero, and this isn't correct.

I'd fire it off to tech support, if they haven't already noticed your post. Please post with the response!

Tom

Super User
Posts: 11,343

Re: HHMMSS SAS ISSUE

Posted in reply to geoonline

A work around would be to read the value as text and if the length is less than 6 to append 0 to make it the needed length and then input as in your example.

I did note that using a explicit length with the format such as hhmmss6. then it reads as seconds. If I used the B8601tm. format it did read 10 minutes but also had 12 seconds?!

PROC Star
Posts: 1,167

Re: HHMMSS SAS ISSUE

If I try

x=input('0010',hhmmss6.);

I'm still getting

x=10:00:00 y=12:30:45

Super User
Posts: 11,343

Re: HHMMSS SAS ISSUE

Version of SAS dependency perhaps, I'm on 9.2.3

Contributor
Posts: 35

Re: HHMMSS SAS ISSUE

Why I got different results:

6032   data _null_;

6033     x=input('0010',hhmmss.);

6034     y=input('123045',hhmmss.);

6035     x2=input('0110',hhmmss.);

6036     x3=input('1210',hhmmss.);

6037     put x=time8. y=time8. x2=time8. x3=time8.;

6038   run;

x=0:00:10 y=12:30:45 x2=0:01:10 x3=0:12:10

PROC Star
Posts: 1,167

Re: HHMMSS SAS ISSUE

This is getting weird!

Geoonline, when you refer this to SAS tech support, be sure to point them at this discussion!!

Tom

Occasional Contributor
Posts: 8

Re: HHMMSS SAS ISSUE

Thanks everyone for the response...I believe the difference in result is due to the SAS version. I have tried it in SAS 9.2 & SAS 9.3, both giving different results.

Super User
Posts: 19,770

Re: HHMMSS SAS ISSUE

Posted in reply to geoonline
Occasional Contributor
Posts: 8

Re: HHMMSS SAS ISSUE

Hi All,

  I contacted SAS Tech Support regarding this issue. They already seem to be aware of this issue and SAS R&D is currrently working on a fix to it.

In the meantime SAS suggests to use B8601TMw.d informat to read in these values correctly.

It's documented here:

http://support.sas.com/documentation/cdl/en/leforinforref/64790/HTML/default/viewer.htm#n0tx8gqdnl4u...

I have tried it with the above examples and it works fine.

Thanks again for all your responses.

Regards,

   Geo

Ask a Question
Discussion stats
  • 9 replies
  • 460 views
  • 0 likes
  • 5 in conversation