Format magic

Super Contributor
Posts: 260

Format magic

Hello all.
I'm a long-time friend of formats, and I was puzzled when this strange thing appened to one of my clients. I can't figure any explanation to this ; maybe one of you would have an idea ?
Question is sent to Tech Support in France, but no answer yet.

The thing is :
1) I create to different formats, which only differ in an extra interval for one of them ;
2) I compute a value which is approximately -50 (due to roundings, the true value is not exactly -50 but I don't think this is really the point, or at least not the ONLY problem)
3) I use these two formats on the same value, and in spite of the same definition of intervals for value -50 in both formats, I end up with two DIFFERENT values !

Amazing, isn't it ?

Here is my sample program :

proc format ;
value pcta -80-<-50 = "A "
-50-<-10 = "B "
-10-high= "X "
;
value pctb -80-<-50 = "A "
-50-<-10 = "B "
;
run;
data test;
x = 3.4-2.8;
y = 2.9-2.6;
pcta = (y-x)/x*100;
run;
proc sql ;
select PUT(pctA,pcta.), PUT(pctA,pctb.)
from test
;
quit ;

Any ideas welcome !
Regards
Olivier
SAS Super FREQ
Posts: 9,364

Re: Format magic

Hi, Olivier:
No answers. Just more questions. The same thing happens when you use a format OUTSIDE of the PUT statement as shown below. Interestingly enough, when I take the subtraction out of the mix, then the format works as expected.
cynthia
*** another example;[pre]
data test;
try=1;
x = 3.4-2.8;
y = 2.9-2.6;
pcta = (y-x)/x*100;
output;

try=2;
x = 3.4000-2.8000;
y = 2.9000 - 2.6000;
pcta = (y-x)/x*100;
output;

try=3;
x = 3.4000-2.8000;
y = 2.9000 - 2.6000;
pcta = (y-x)/x*100.00;
output;

try=4;
x = .60000000;
y = .30000000;
pcta = (y-x)/x*100;
output;

try=5;
x = .488888;
y = .244444;
pcta = (y-x)/x*100;
output;

try=6;
x = .5;
y = .25;
pcta = (y-x)/x*100;
output;

try=7;
x = .750000;
y = .350000;
pcta = (y-x)/x*100;
output;

try=8;
x = .75000;
y = .37500;
pcta = (y-x)/x*100;
output;

try=9;
x = .75000;
y = .37499;
pcta = (y-x)/x*100;
output;

try=10;
x = .75000;
y = .37511;
pcta = (y-x)/x*100;
output;
run;

proc report data=test nowd;
column try x y pcta pcta=two pcta=three;
define pcta / display 'Unformatted pcta' width=12;
define two / display format=pcta. 'with pcta fmt' width=5;
define three / display format=pctb. 'with pctb fmt' width=5;
run;
[/pre]
Super Contributor
Posts: 260

Re: Format magic

Cynthia, I'm glad that it is not a silly question and that it can also puzzle the SAS people. Anyway, you managed to add a Report procedure in the problem, this sounds like you're report-addicted !!! :-)

Anyway, something weirder, since it doesn't seem to be related in any way, yet solves the problem :

proc format ;
value pcta (NOTSORTED)
-80-<-50 = "A "
-50-<-10 = "B "
-10-high= "X "
;
value pctb -80-<-50 = "A "
-50-<-10 = "B "
;
run;

Adding the NOTSORTED option makes both formats work the same way. But it doesn't sound more logical to me anyway.

I already solved the problem adding a FUZZ option to the format. What I want is to understand what's happening here, and how adding intervals can disturb the way a formats handle the same value !

Have a nice weekend (time to flee from work, here in France) !
Olivier
Discussion stats
• 2 replies
• 136 views
• 0 likes
• 2 in conversation