Programming the statistical procedures from SAS

about the precision of a numeric variable in a dataset

Reply
SAS Employee kwu
SAS Employee
Posts: 34

about the precision of a numeric variable in a dataset

when I define a numeric variable (or attrib) in a dataset, since the variable would only have value in the range of 1-9000K, so I would like to define the length of variable to be 4 (bytes). based on rule in other database ststem, a 4 bytes integer should be able to handle max value of 2147483647. However, when try to insert a value greater than 2500k, it starts having the round off error, SAS does not complian the overflow (no warning or error) but just insert it with round off error.
I am trying to understand how sas stores the numeric value with different length and how to calculate the safe data range for a specified length? Also is there a way to add a check constrain to let SAS to spit an error when overflow happens?

I am new to SAS, any suggestion would be high appreciated.
Regular Contributor
Posts: 169

Re: about the precision of a numeric variable in a dataset

I don't know where you are getting your value of 2147483647 as the maximum integer value that could be stored precisely in 4 bytes. SAS documentation for both Windows and Unix environments indicates that the largest integer value which can be precisely stored in 4 bytes is 2097152, far smaller than 9000K=9000000. A 5 byte variable can precisely represent integer values through 536870912, so increasing your variable length by 1 byte would solve your problem here.

I would note that this question is much more about Base SAS than it is about SAS Statistical Procedures. In fact, I would say that there is really nothing in this post that has to do with Statistical Procedures. You would be likely to get a much better, more knowledgeable response if you posted your problem in the proper forum. Might I suggest the SAS Macro Facility, Data Step and SAS Language Elements forum.
SAS Employee kwu
SAS Employee
Posts: 34

Re: about the precision of a numeric variable in a dataset

Dale:
thank you. that value is from other programming language like fortran or c for a 4 bytes integer.

could you please send me the doc where you find the precisely stored value for 4 bytes? I could not find it in SAS help.

I did mean to post it in data step and sas langugae element forum but I was browsing each one and did not realize that I posted on the wrong forum. Thank you for the suggestion though.
Regular Contributor
Posts: 169

Re: about the precision of a numeric variable in a dataset

Here is a link that gives the byte specification and maximum integer values on a Windows OS:

http://support.sas.com/onlinedoc/913/getDoc/en/hostwin.hlp/numvar.htm
Ask a Question
Discussion stats
  • 3 replies
  • 120 views
  • 0 likes
  • 2 in conversation