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.
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.