BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
pcfriendly
Calcite | Level 5

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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.

View solution in original post

5 REPLIES 5
Tom
Super User Tom
Super User

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

pcfriendly
Calcite | Level 5

Thanks Tom,

The number is being entered as 22 though?

Is there a way to make it not round the number?

Tom
Super User Tom
Super User

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.

pcfriendly
Calcite | Level 5

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?

pcfriendly
Calcite | Level 5

Thanks Tom,

I changed the PERCENT6 TO PERCENT8 & it now calculates correctly.

Many thanks !!

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
  • 5 replies
  • 1688 views
  • 3 likes
  • 2 in conversation