Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 03-31-2022 10:15 AM
(1085 views)

Hi there,

I'm running an analysis where I am looking at weight change in a population of 9472 people. I have the equation: follow up weight - baseline weight = weight change. However, when I looked into the calculations, instead of producing exact values, SAS seems to have rounded to a similar value for a bunch of observations. For example, there is an observation that the equation is 89.813-88.45 = 1.363, but SAS rounds this to 1.3608, along with a bunch of other observations. Is there a reason it does this, and a way to make it not do this?

Thank you for the help!

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I suspect you are looking at formatted numbers, which means that they are rounded to some precision by PROC PRINT or some other SAS procedure. SAS computes numbers using double-precision computations, but it displays only a portion of the raw values. If a variable has a format, the format determines the precision. Otherwise, a default format is used.

To see more precision, use the FORMAT statement to explicitly set the format for the columns of values. For example, to get 6 decimal digits for each value, use

```
proc print data=have;
format FollowupWeight BaselineWeight DiffWeight 10.6;
var FollowupWeight BaselineWeight DiffWeight;
run;
```

If you are not using PROC PRINT but are using some other method to view the data, please specify how you are obtaining these numbers.

4 REPLIES 4

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I say that you should 1) provide the starting values, 2) the code you use to calculate the result, 3) the formats assigned to the variables and 4) the result that you find incorrect.

Since SAS always has a format assigned to value you need to show us the format because the values you claim in 89.813-88.45 could be rounded by the format assigned. A format of 8.3 for example will display any value between 89.8125 to 89.81349 as 89.813 and similar with that 88.45. So just typing values does not always mean the value you see is what is used by SAS as those not-displayed not-rounded decimals will be used in calculations.

The data values should be in the form of data step code. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the <> icon or attached as text to show exactly what you have and that we can test code against.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I suspect you are looking at formatted numbers, which means that they are rounded to some precision by PROC PRINT or some other SAS procedure. SAS computes numbers using double-precision computations, but it displays only a portion of the raw values. If a variable has a format, the format determines the precision. Otherwise, a default format is used.

To see more precision, use the FORMAT statement to explicitly set the format for the columns of values. For example, to get 6 decimal digits for each value, use

```
proc print data=have;
format FollowupWeight BaselineWeight DiffWeight 10.6;
var FollowupWeight BaselineWeight DiffWeight;
run;
```

If you are not using PROC PRINT but are using some other method to view the data, please specify how you are obtaining these numbers.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Here's an example that shows how a format could lead you to think that the values were miscalculated:

```
data test;
x1 = 89.813;
x2 = 88.4522;
x3 = x1 - x2;
format x2 8.2;
run;
proc print data=test;
run;
```

Result:

Beob. x1 x2 x3 1 89.813 88.45 1.3608

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

How certain are you that A and B actually have EXACTLY those values?

64 data test; 65 a=89.813; 66 c=1.3608; 67 b=a-c; 68 put b= b= 8.2; 69 run; b=88.4522 b=88.45

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. **Registration is now open through August 30th**. Visit the SAS Hackathon homepage.

Upcoming Events

- SAS Bowl XLII, The SAS Hackathon 2024 | 14-Aug-2024
- Ask the Expert: Top Tips for SAS®9 Programmers Moving to SAS® Viya® | 15-Aug-2024
- Ask the Expert: Workload Orchestration in SAS® Viya® 4 | 22-Aug-2024
- Ask the Expert: Solving Multi-Objective Optimization Models in SAS® Optimization | 29-Aug-2024
- WUSS 2024 | 04-Sep-2024
- Ask the Expert: Executing SAS Analytics From R Shiny Applications | 05-Sep-2024
- Ask the Expert: How Do I Perform Customer Segmentation With SAS Intelligent Decisioning? | 12-Sep-2024

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.