In the below code the 1st 4 values, read in, equal the 5th value, but after conversion from character to numeric the comparision statement is always false. I have read several sites via Google, but have been unable to determine what I am doing wrong. If I put a ROUND function on the SUM statement (to .00001), the values are considered equal. I would like to use the values in subsequent processing and not have to use the ROUND function to check my computations. I am really interested in understandning this problem, thanks for your help.
data HAVE;
Format a a_num b b_num c c_num d d_num TOTAL TOTAL_num;
Length a b c d TOTAL $100;
infile datalines delimiter="~" dsd;
input a $ b $ c $ d $ TOTAL $;
a_num=input(a,comma18.);
b_num=input(b,comma18.);
c_num=input(c,comma18.);
d_num=input(d,comma18.);
TOTAL_num=input(TOTAL,comma18.);
datalines;
1,567,378.77~953,466.02~50,949.03~532.82~2,572,326.64
15,884,327.48~7,330,140.68~559,032.01~1,743.28~23,775,243.45
165,119.70~44,705.58~~~209,825.28
;
data WANT;
Format CHECK;
Set HAVE;
SUM_TOTAL=sum(a_num,b_num,c_num,d_num);
If sum_total^=TOTAL_num then CHECK="X";
Format a_num b_num c_num d_num TOTAL_num SUM_TOTAL comma18.2;
Run;
... View more