Hi there,
I'm running an analysis where I am looking at weight change in a population of 9472 people. I have the equation: follow up weight - baseline weight = weight change. However, when I looked into the calculations, instead of producing exact values, SAS seems to have rounded to a similar value for a bunch of observations. For example, there is an observation that the equation is 89.813-88.45 = 1.363, but SAS rounds this to 1.3608, along with a bunch of other observations. Is there a reason it does this, and a way to make it not do this?
Thank you for the help!
I suspect you are looking at formatted numbers, which means that they are rounded to some precision by PROC PRINT or some other SAS procedure. SAS computes numbers using double-precision computations, but it displays only a portion of the raw values. If a variable has a format, the format determines the precision. Otherwise, a default format is used.
To see more precision, use the FORMAT statement to explicitly set the format for the columns of values. For example, to get 6 decimal digits for each value, use
proc print data=have;
format FollowupWeight BaselineWeight DiffWeight 10.6;
var FollowupWeight BaselineWeight DiffWeight;
run;
If you are not using PROC PRINT but are using some other method to view the data, please specify how you are obtaining these numbers.
I say that you should 1) provide the starting values, 2) the code you use to calculate the result, 3) the formats assigned to the variables and 4) the result that you find incorrect.
Since SAS always has a format assigned to value you need to show us the format because the values you claim in 89.813-88.45 could be rounded by the format assigned. A format of 8.3 for example will display any value between 89.8125 to 89.81349 as 89.813 and similar with that 88.45. So just typing values does not always mean the value you see is what is used by SAS as those not-displayed not-rounded decimals will be used in calculations.
The data values should be in the form of data step code. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the <> icon or attached as text to show exactly what you have and that we can test code against.
I suspect you are looking at formatted numbers, which means that they are rounded to some precision by PROC PRINT or some other SAS procedure. SAS computes numbers using double-precision computations, but it displays only a portion of the raw values. If a variable has a format, the format determines the precision. Otherwise, a default format is used.
To see more precision, use the FORMAT statement to explicitly set the format for the columns of values. For example, to get 6 decimal digits for each value, use
proc print data=have;
format FollowupWeight BaselineWeight DiffWeight 10.6;
var FollowupWeight BaselineWeight DiffWeight;
run;
If you are not using PROC PRINT but are using some other method to view the data, please specify how you are obtaining these numbers.
Here's an example that shows how a format could lead you to think that the values were miscalculated:
data test;
x1 = 89.813;
x2 = 88.4522;
x3 = x1 - x2;
format x2 8.2;
run;
proc print data=test;
run;
Result:
Beob. x1 x2 x3 1 89.813 88.45 1.3608
How certain are you that A and B actually have EXACTLY those values?
64 data test; 65 a=89.813; 66 c=1.3608; 67 b=a-c; 68 put b= b= 8.2; 69 run; b=88.4522 b=88.45
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.