chg=aval- base;
....
run;
why? get the value -0.2999999999? how to modify it?
SAS (and all computer software) stores numbers in a binary form, and so some decimal values cannot be represented exactly, this is not possible and not avoidable.
However, you can change the way the numbers are displayed, so if you assign a format to CHG, then it displays with one decimal place. For example:
format chg 8.1;
The root cause is how computers store numbers. Details here.
And here some coding options for dealing with it.
data test;
aval=51.6;
base=51.9;
chg=aval-base;
chg1=round(aval-base,.0000000001);
chg2=aval-base;
chg3=sum(aval,-base);
format chg2 best32.1;
run;
proc print data=test;
run;
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!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.