turn on suggestions

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

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- different results of mean after sorting

Topic Options

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

11-20-2017 04:22 PM

Hi,

i have set with one numeric variable which gives me different results of mean when sorted.

data b;

format a best20.;

input a;

datalines;

0.187

0.171

0.183

0.08

;

;run;

proc sort data=b; by a;run;

proc summary data=b nway missing noprint mean ;

var a;

output out = out_b mean=mean ;

RUN;

result when sorted =0.15525

result when not sorted = 0.15524999999999

WHY ?!?!

Accepted Solutions

Solution

11-20-2017
04:35 PM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Jedrzej

11-20-2017 04:31 PM

https://communities.sas.com/t5/Base-SAS-Programming/proc-summary-calculating-mean/m-p/414821

Jedrzej wrote:

WHY ?!?!

RTM - there's an entire chapter on this topic and it's not really a SAS issue, it's a 'binary computer issue'.

All Replies

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Jedrzej

11-20-2017 04:25 PM

This exact problem has been discussed in great length. Please search today's posts, and you will find the answer.

But why are you posting this anyway, a duplicate of an earlier thread? Is it homework?

--

Paige Miller

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to PaigeMiller

11-20-2017 04:31 PM - edited 11-20-2017 04:32 PM

my friend asked me today about it and i didn't find soultion for this. I was curious so i posted this question, didn't know he done the same.

sorry,

Solution

11-20-2017
04:35 PM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Jedrzej

11-20-2017 04:31 PM

https://communities.sas.com/t5/Base-SAS-Programming/proc-summary-calculating-mean/m-p/414821

Jedrzej wrote:

WHY ?!?!

RTM - there's an entire chapter on this topic and it's not really a SAS issue, it's a 'binary computer issue'.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Jedrzej

11-20-2017 05:19 PM

Looking at all possible ways to order those four numbers we see that there are two different means that can result.

```
data _null_;
array x (4) (0.187 0.171 0.183 0.08) ;
do j=1 to fact(dim(x));
call allperm(j, of x[*]);
mean=mean(of x(*)) ;
put j= z2. (x:) (=) mean= best20.18;
end;
run;
```

j=01 x1=0.187 x2=0.171 x3=0.183 x4=0.08 mean=0.15524999999999 j=02 x1=0.187 x2=0.171 x3=0.08 x4=0.183 mean=0.15525 j=03 x1=0.187 x2=0.08 x3=0.171 x4=0.183 mean=0.15525 j=04 x1=0.08 x2=0.187 x3=0.171 x4=0.183 mean=0.15525 j=05 x1=0.08 x2=0.187 x3=0.183 x4=0.171 mean=0.15525 j=06 x1=0.187 x2=0.08 x3=0.183 x4=0.171 mean=0.15525 j=07 x1=0.187 x2=0.183 x3=0.08 x4=0.171 mean=0.15525 j=08 x1=0.187 x2=0.183 x3=0.171 x4=0.08 mean=0.15525 j=09 x1=0.183 x2=0.187 x3=0.171 x4=0.08 mean=0.15525 j=10 x1=0.183 x2=0.187 x3=0.08 x4=0.171 mean=0.15525 j=11 x1=0.183 x2=0.08 x3=0.187 x4=0.171 mean=0.15525 j=12 x1=0.08 x2=0.183 x3=0.187 x4=0.171 mean=0.15525 j=13 x1=0.08 x2=0.183 x3=0.171 x4=0.187 mean=0.15525 j=14 x1=0.183 x2=0.08 x3=0.171 x4=0.187 mean=0.15525 j=15 x1=0.183 x2=0.171 x3=0.08 x4=0.187 mean=0.15525 j=16 x1=0.183 x2=0.171 x3=0.187 x4=0.08 mean=0.15524999999999 j=17 x1=0.171 x2=0.183 x3=0.187 x4=0.08 mean=0.15524999999999 j=18 x1=0.171 x2=0.183 x3=0.08 x4=0.187 mean=0.15525 j=19 x1=0.171 x2=0.08 x3=0.183 x4=0.187 mean=0.15525 j=20 x1=0.08 x2=0.171 x3=0.183 x4=0.187 mean=0.15525 j=21 x1=0.08 x2=0.171 x3=0.187 x4=0.183 mean=0.15525 j=22 x1=0.171 x2=0.08 x3=0.187 x4=0.183 mean=0.15525 j=23 x1=0.171 x2=0.187 x3=0.08 x4=0.183 mean=0.15525 j=24 x1=0.171 x2=0.187 x3=0.183 x4=0.08 mean=0.15524999999999