Read data as ib, but should have been pd... can I convert?

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

Read data as ib, but should have been pd... can I convert?

Reading a mainframe data file, I used informat ib8.2 instead of pd8.2 - this wasn't caught for a couple of weeks and the original files are no longer available.  Is there a way to convert the incorrectly read value to what it should be?


Accepted Solutions
Solution
‎07-09-2012 03:48 PM
Super User
Posts: 5,516

Re: Read data as ib, but should have been pd... can I convert?

Posted in reply to KiwiSteve

KiwiSteve,

There is no way to get back the exact value.  Some of the value has already been discarded by SAS, because the number of significant digits in ib8 is larger than what SAS can store exactly as a numeric.  SAS stores its numerics in a real binary form using 8 bytes, leaving either approximately 6.5 or 7 bytes to hold the binary value (depends on the operating system).  You have already read in 8 bytes and treated it as a binary value, so SAS will have lost the sign as well as some of the significant digits from the end of the value.  If an approximate value is valuable to you, we can explore some possibilities.

If your actual values were smaller, and started with leading 0000s, it may be possible to recover the full value for this records.

View solution in original post


All Replies
Super User
Super User
Posts: 7,074

Re: Read data as ib, but should have been pd... can I convert?

Posted in reply to KiwiSteve

You should be able to reverse it using PUT and INPUT functions.

want = input( put(have,ib8.2), pd8.2) ;

New Contributor
Posts: 4

Re: Read data as ib, but should have been pd... can I convert?

Hi Tom, thanks for suggesting that, but I had tried something similar without any luck.  The problem seems to be getting the ib value...

I have attached a portion of the log that shows the ib value is not being found.

(Sorry about the attachment, but my work machine seems to be restricted as I couldn't just cut & paste it into the post).

Message was edited by: Stephen Mosen

Attachment
Super User
Super User
Posts: 7,074

Re: Read data as ib, but should have been pd... can I convert?

Posted in reply to KiwiSteve

I think the problem is that your example value of 12345.67 is not a value that could have been generated by a PD8.2 format originally. Converting that to IB8.2 format yields '000000000012D687'x which as one nibble with a value of 'D'x which cannot be translated by the PD format.  PD format would only have nibbles with values from 0 to 9.

Did you try it with the actual values in your data?

New Contributor
Posts: 4

Re: Read data as ib, but should have been pd...  can I convert?

I didn't think it would matter what my test values were...

The original file had packed (pd) fields that I read in using ib informat, giving just a normal numeric value.  The trouble is if I use an ib format to try and reverse the process, I just get an ib-value and not the original pd-value.

Solution
‎07-09-2012 03:48 PM
Super User
Posts: 5,516

Re: Read data as ib, but should have been pd... can I convert?

Posted in reply to KiwiSteve

KiwiSteve,

There is no way to get back the exact value.  Some of the value has already been discarded by SAS, because the number of significant digits in ib8 is larger than what SAS can store exactly as a numeric.  SAS stores its numerics in a real binary form using 8 bytes, leaving either approximately 6.5 or 7 bytes to hold the binary value (depends on the operating system).  You have already read in 8 bytes and treated it as a binary value, so SAS will have lost the sign as well as some of the significant digits from the end of the value.  If an approximate value is valuable to you, we can explore some possibilities.

If your actual values were smaller, and started with leading 0000s, it may be possible to recover the full value for this records.

New Contributor
Posts: 4

Re: Read data as ib, but should have been pd... can I convert?

Posted in reply to Astounding

Thanks Astounding - I was beginning to think it was unrecoverable, but thanks for confirming that and explaining why.  Approximate values would not be acceptable, so I'll just take the hit on the corrupt data.

Cheers,

Steve

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 332 views
  • 0 likes
  • 3 in conversation