DATA Step, Macro, Functions and more

Unable to get expected results while comparing Negative Numbers using Proc Compare

Reply
Occasional Contributor PA8
Occasional Contributor
Posts: 8

Unable to get expected results while comparing Negative Numbers using Proc Compare

Hi Everyone,

 

I am comparing two Numeric Negative values in two columns within the same data set using Proc Compare and Method=Absolute. However, I am not getting some of the unmatched/expected records - for example values -2.75 and -2.74 do not come up in the output?

 

The columns/values have same precision, length and format as 5.2.

 

I have tried to search in our community for related topics and implemented Round() and Trunc() functions on the values before using them in Proc Compare function but no success. Can anyone please help as its urgent.

 

proc compare base = com_edc_cov Method=Absolute Criterion= 0.01 listall briefsummary ; var EDC_SDS; with SDS;
id SUBJECTNUMBERSTR Visit lbcat;
run;

 

Thanks so much !

Super User
Posts: 22,874

Re: Unable to get expected results while comparing Negative Numbers using Proc Compare

Check the CRITERION would be my starting point. Setting it at 0.01 and not detecting 0.01 sets off flags in my head.

Super User
Posts: 13,084

Re: Unable to get expected results while comparing Negative Numbers using Proc Compare

Note that

The columns/values have same precision, length and format as 5.2.

Does not mean that SAS sees the values as -2.75 when doing comparisons if the internal value is actually -2.7499356 or such. Format controls what is displayed not stored.

 

Consider:

data example;
   x = -2.744;
   y = -2.749;
   z = abs(y-x);
   put x= f5.2 y=f5.2 z= f6.4;
run;

the value for the absolute difference is less than 0.01, your criterion setting so they would be considered equal by proc compare even though they will display a -2.74 and -2.75

 

Occasional Contributor PA8
Occasional Contributor
Posts: 8

Re: Unable to get expected results while comparing Negative Numbers using Proc Compare

Thank you so much for your help! Yes, I changed the Criterion to .001 but in that case I start getting values that are equal for eg

-2.09 and -2.09,

-2.28 and -2.28 etc

 

So, increasing Criterion is not helpful either.

 

I tried example below :-

 

z = abs(EDC_SDS - SDS);
put EDC_SDS = f5.2 SDS = f5.2 z = f6.4;

if z eq 0 then output;

 

I am getting whole dataset as the output since the z has values such as -

 

EDC_SDS=0.11 SDS=0.11 z=0.0049, EDC_SDS=-2.32 SDS=-2.32 z=0.002

I want output only if there is difference in EDC_SDS and SDS values.

 

Best !

Occasional Contributor PA8
Occasional Contributor
Posts: 8

Re: Unable to get expected results while comparing Negative Numbers using Proc Compare

Quick correction - Apologies :

 

The output is 0 records.

Super User
Posts: 22,874

Re: Unable to get expected results while comparing Negative Numbers using Proc Compare

Do your comparison manually and make sure to round the numbers first to the level of precision you want compared. 

PROC COMPARE is nice but it needs a lot of improvement in my experience and it's usually easier in the long run to roll my own. 

Super User
Posts: 13,084

Re: Unable to get expected results while comparing Negative Numbers using Proc Compare


PA8 wrote:

Thank you so much for your help! Yes, I changed the Criterion to .001 but in that case I start getting values that are equal for eg

-2.09 and -2.09,

-2.28 and -2.28 etc

 


There are times when you really want to round the values in a data step before use or comparisons.

Ask a Question
Discussion stats
  • 6 replies
  • 92 views
  • 2 likes
  • 3 in conversation