BookmarkSubscribeRSS Feed
Romain69100
Fluorite | Level 6

Dear SAS users,

 

I am currently working on a project where i built a numeric score called "SCORE", this variable range from 0 to 0.90 with the following modalities:

-0.2

-0.31

-0.40

-0.60

-0.75

-0.80

-0.90

 When i performed a proc freq on this variable i got effective by modalities. However when i tried this code:

data toto;

set toto;

if score=0.2 then output;

run;

0 observation is printed. I have the same problem with the 0.31 value. It worked well for the other values....

I have checked number of decimals and format and it is well set up.

 

I do not know what is happening and why i get an output with the proc freq but nothing with the data step...

Any help would be grandly appreciated.

 

Thanks

 

 

16 REPLIES 16
PaigeMiller
Diamond | Level 26

@Romain69100 wrote:

Dear SAS users,

 

I am currently working on a project where i built a numeric score called "SCORE", this variable range from 0 to 0.90 with the following modalities:

-0.2

-0.31

-0.40

-0.60

-0.75

-0.80

-0.90

 When i performed a proc freq on this variable i got effective by modalities. However when i tried this code:

data toto;

set toto;

if score=0.2 then output;

run;

0 observation is printed. I have the same problem with the 0.31 value. It worked well for the other values....

I have checked number of decimals and format and it is well set up.

 

I do not know what is happening and why i get an output with the proc freq but nothing with the data step...

Any help would be grandly appreciated.


Are there errors or warnings in the log? If so, show us the ENTIRE log for this DATA step (we need to see every single line, every single character — do not pick and choose parts of the log to show us and not show us the rest of the log). Please click on the </> icon and paste the log as text into the window that appears.

Insert Log Icon in SAS Communities.png

 

The first possibility that comes to mind is that SCORE is actually a character variable and it does not have value 0.2 but its value is character string '0.2'. You should get errors in the log if this is the case. 

 

The second possibility is that SCORE is numeric but its value is for some reason is not 0.2 in your data set but some value that is extremely close to 0.2 but not exactly equal because of round-off error or machine precision problems. 

--
Paige Miller
Romain69100
Fluorite | Level 6

Thank you for your answer. No warnings/errors in the log. Score is numeric and i have only 2 decimals... It worked well for other values but for some reasons not for 0.20 and 0.31....

Reeza
Super User

Suspect this is a numeric precision issue, does the following work:

 

data toto2;

set toto;

if round(score, 0.1)=0.2 then output;

run;

Romain69100
Fluorite | Level 6

Thank you for your answer. I have only 2 decimals for all score values. It worked well for other values but for some reasons not for 0.20 and 0.31....

PaigeMiller
Diamond | Level 26

@Romain69100 wrote:

Thank you for your answer. I have only 2 decimals for all score values. It worked well for other values but for some reasons not for 0.20 and 0.31....


You mean IT LOOKS LIKE you have only two digits ... the real value could be something different. The real value could really be (even if you don't see it) 0.1999999999999 (and so SAS shows you 0.2) and this is not equal to 0.2. So you could try something like this to test if this is what is happening.

 

if fuzz(score - 0.2) = 0 then output;

 

--
Paige Miller
Romain69100
Fluorite | Level 6

 Thanks i tried  your code and it does not fix the problem. 0.20 and 0.31 are the REAL values

Reeza
Super User

Is it -0.2 and -0.31 or 0.2 and 0.31?

 


@Romain69100 wrote:

 Thanks i tried  your code and it does not fix the problem. 0.20 and 0.31 are the REAL values


 

 

Reeza
Super User

@Romain69100 wrote:

Thank you for your answer. I have only 2 decimals for all score values. It worked well for other values but for some reasons not for 0.20 and 0.31....


Numerical Accuracy in SAS:

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lrcon/p0ji1unv6thm0dn1gp4t01a1u0g6.htm

 

Did the code work?

Kurt_Bremser
Super User

@Romain69100 wrote:

Thank you for your answer. I have only 2 decimals for all score values. It worked well for other values but for some reasons not for 0.20 and 0.31....


Did you actually try the ROUND function? If not, DO IT.

Romain69100
Fluorite | Level 6

Yes i tried it. The problem is still present. It is not a decimal/round problem because 0.20 and 0.31 are the real and entire values.. 

Reeza
Super User

Please read the previous article I linked, and post the log from the code I posted. below.

Forgot the negative sign.

 

data toto2;

set toto;

if round(score, 0.1)=-0.2 then output;

run;
PaigeMiller
Diamond | Level 26

@Reeza wrote:

Please read the previous article I linked, and post the log from the code I posted. below.

Forgot the negative sign.

 

data toto2;

set toto;

if round(score, 0.1)=-0.2 then output;

run;

@Reeza , this not only would output values of -0.2 but it would also output when the value is -0.22, which doesn't seem like a good general purpose strategy here.

--
Paige Miller
Reeza
Super User

OP has stated those values are not possibly in the data set though and easily adjusted for two decimal places if this is the issue.

 


@PaigeMiller wrote:

@Reeza wrote:

Please read the previous article I linked, and post the log from the code I posted. below.

Forgot the negative sign.

 

data toto2;

set toto;

if round(score, 0.1)=-0.2 then output;

run;

@Reeza , this not only would output values of -0.2 but it would also output when the value is -0.22, which doesn't seem like a good general purpose strategy here.


 

PaigeMiller
Diamond | Level 26

@Romain69100 

I think this has gone on long enough with us guessing what is happening. We need to see (a portion of) your actual data set as SAS data step code (please follow these instructions); and we need to see the code you are using.

--
Paige Miller

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 16 replies
  • 975 views
  • 3 likes
  • 5 in conversation