BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi
I am trying to run below sas code and its giving me unexpected result.Can I have help on this.


In both case1 and case2 val3 is assigned -600 but the value of val4 derived from the format is differing.


proc format;
Value u33mbchg

low - -600 = ' 94.7649 '

-600 <- -200 = ' 95.8705 '

-200 <- -100 = ' 99.4335 '

-100 <- high = ' 100.9247 ' ;

run;



case1:

Data T1;

val1=sum(440.0001,0.01);

val2=sum(1040.0001,0.01);

val3=Sum(0,val1)-Sum(0,val2);

val4 = 1*put(val3,u33mbchg.);

run;

output
val1=440.0101
val2=1040.0101
val3=-600
val4=94.7649




Using the above proc format we ran the same code with different input value in val1 and val2 as below:

case2:
Data T1;

val1=sum(440.1,0.01);

val2=sum(1040.1,0.01);

val3=Sum(0,val1)-Sum(0,val2);

val4 = 1*put(val3,u33mbchg.);

run;

output:
val1=440.11
val2=1040.11
val3=-600
val4=95.8705
2 REPLIES 2
Diane_SAS
SAS Employee
What value do you expect to be the correct one for val4?
hdo
SAS Employee hdo
SAS Employee
Due to the ( lack of ) precision in floating point operations on the computer , the value val3 is nor excactly -600 in both cases.

insert
valx=val3+600;
put valx= 20.15;

in each data step and you will see

valx=0.000000000000000
and
valx=0.000000000000114
and since the format is separated on either side of -600 , the results differ.
At least on mi Intel based computer.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 625 views
  • 0 likes
  • 3 in conversation