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
1 REPLY 1
Olivier
Pyrite | Level 9
This rather looks like a rounding problem, than a format problem.
ROUNDing the result of your VAL3 variable to, say, 0.0001 would work just fine.

val3=ROUND (Sum(0,val1)-Sum(0,val2), .0001) ;

See problems and discussions about SAS rounding in the documentation :
http://support.sas.com/onlinedoc/913/getDoc/fr/lrcon.hlp/ a000695157.htm (you have to suppress the space character in the web adress, but if I don't type it, I have .ht displayed instead of .htm).

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 1 reply
  • 575 views
  • 0 likes
  • 2 in conversation