- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I ran the below code and got the below outputs in the DS1, DS2 & Comb1 tables.
1. But I want the decimal values (E power) to be printed/stored in the same format how I defined in the Data Steps. i.e I want to remove the Exp power values into normal decimal values as defined in the Data steps.
2. If you observe in the output table COMB1, I am NOT getting 0 under D Column though Col A & Col B are equal Instead I am getting some decimal values. In turn the value under A_eq_B column doesnt Contains "Yes". This is the case for Row No-3 & 8.
Really It is surprising to know how SAS taking D=a-b?
Can you please help me on this?
data ds1;
do A = .1 to .8 by .1;
Index + 1;
output;
end;
Index = 21;
A = 0.000000002;
output;
Index = 22;
A = 0.000000002;
output;
run;
data ds2;
do B = .1,.2,.3,.4,.5,.6,.7,.8;
Index + 1;
output;
end;
Index = 21;
B = 0.000000002;
output;
Index = 22;
B = 0.000000003;
output;
run;
data comb1;
merge ds1 ds2;
by Index;
D=a-b;
if A = B then A_eq_B = "Yes";
if round(A,0.01) = round(B,0.01) then A_eq_B_1 = "Yes";
run;
DS1:
A | Index |
0.1 | 1 |
0.2 | 2 |
0.3 | 3 |
0.4 | 4 |
0.5 | 5 |
0.6 | 6 |
0.7 | 7 |
0.8 | 8 |
2E-9 | 21 |
2E-9 | 22 |
DS2:
B | Index |
0.1 | 1 |
0.2 | 2 |
0.3 | 3 |
0.4 | 4 |
0.5 | 5 |
0.6 | 6 |
0.7 | 7 |
0.8 | 8 |
2E-9 | 21 |
3E-9 | 22 |
COMB1:
A | Index | B | D | A_eq_B | A_eq_B_1 |
0.1 | 1 | 0.1 | 0 | Yes | Yes |
0.2 | 2 | 0.2 | 0 | Yes | Yes |
0.3 | 3 | 0.3 | 5.5555115E-17 | Yes | |
0.4 | 4 | 0.4 | 0 | Yes | Yes |
0.5 | 5 | 0.5 | 0 | Yes | Yes |
0.6 | 6 | 0.6 | 0 | Yes | Yes |
0.7 | 7 | 0.7 | 0 | Yes | Yes |
0.8 | 8 | 0.8 | -1.11022E-16 | Yes | |
2E-9 | 21 | 2E-9 | 0 | Yes | Yes |
2E-9 | 22 | 3E-9 | -1E-9 |
Yes |
Thank a Lot In advance.
Regards,
Ravi SPR
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What you're looking at is primarily a presentation issue. The default format for numeric does not cater for so many decimals. That's why SAS reverts to the scientific ("E") notation. Always keep in mind that what you see is not exactly always what you have.
Use the format statement to handle this. Also, read up on numeric precision in SAS. This is a very interesting topic and can be very helpful in your case. As you are actually trying fuzzy comparison, also have a look at the FUZZ() function.
in your case this should help:
data comb1;
merge ds1 ds2;
by Index;
format a b d comma12.10;
D=a-b;
if A = B then
A_eq_B = "Yes";
if round(A,0.01) = round(B,0.01) then
A_eq_B_1 = "Yes";
run;
Hope this helps,
- Jan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What you're looking at is primarily a presentation issue. The default format for numeric does not cater for so many decimals. That's why SAS reverts to the scientific ("E") notation. Always keep in mind that what you see is not exactly always what you have.
Use the format statement to handle this. Also, read up on numeric precision in SAS. This is a very interesting topic and can be very helpful in your case. As you are actually trying fuzzy comparison, also have a look at the FUZZ() function.
in your case this should help:
data comb1;
merge ds1 ds2;
by Index;
format a b d comma12.10;
D=a-b;
if A = B then
A_eq_B = "Yes";
if round(A,0.01) = round(B,0.01) then
A_eq_B_1 = "Yes";
run;
Hope this helps,
- Jan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Really Superb. Thanks a lot Jan.
The links & code you sent me are perfect & very informative and working fine to my case.
I have been applying different formats/Input function to get rid of this issue since 2 days.But no luck.
And I thought Comma format is only to get commas in the values So i didn't try this format before.
Thank You!
RaviSPR