Hi,
I'm using SAS EG 4.3 with Windows 7 & am trying to perform a calculation of a % of a Currency amount.
Example, I have 2 Fileds on a table, Sales (Currency) & Allocation (%) - NOTE the datatypes appear as shown ie; $ & %.
I go to Query Builder >> Add the 2 Fields to the Builder >> go to Add Computed Column >> Select Advanced Expression & enter;
t1.Sales*Allocation.
The figures for this example are Currency is $180.00 & the Percentage is 22%.
The result for 22% of $180.00 should be $39.60 but I am getting $38.74 ??
I then reloaded my % Field as a Number datatype & tried the below;
t1.Sales*(Allocation/100) same result ...
My goal is to apply the % Allocation figure against the sales figure to get the % of the Sales in this new Column.
Any help appreciated.
I cannot see how entering the number as 22 (or really 0.22) could cause it to get that far off.
If you are storing the value in a permanent dataset make sure that the length of the variable is 8. On machines that use IEEE floating point (unix and windows) you can store numbers in as little as 3 bytes, but then SAS just throws away the rest of the bits used to represent the floating point number. If you try to store .22 into just 3 bytes when you read it back you get. 0.2199707031.
On an IBM mainframe you can even define a numeric variable as length 2, but even then it should not get as low as 0.21522222.
From the $ amount you are getting it looks the percentage is less than 22% and it is just being rounded in your display.
s=180 p=0.22 n=39.6
s=180 p=0.2152222222 n=38.74
Thanks Tom,
The number is being entered as 22 though?
Is there a way to make it not round the number?
I cannot see how entering the number as 22 (or really 0.22) could cause it to get that far off.
If you are storing the value in a permanent dataset make sure that the length of the variable is 8. On machines that use IEEE floating point (unix and windows) you can store numbers in as little as 3 bytes, but then SAS just throws away the rest of the bits used to represent the floating point number. If you try to store .22 into just 3 bytes when you read it back you get. 0.2199707031.
On an IBM mainframe you can even define a numeric variable as length 2, but even then it should not get as low as 0.21522222.
OK, The length of the field is 8, the Type is Number & the Source Informat / Output Format / Output Informat are all PERCENT6.
Could the PERCENT6 be the problem?
Thanks Tom,
I changed the PERCENT6 TO PERCENT8 & it now calculates correctly.
Many thanks !!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.