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

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 ?!?! 
1 ACCEPTED SOLUTION

Accepted Solutions
4 REPLIES 4
PaigeMiller
Diamond | Level 26

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
Jedrzej
Obsidian | Level 7

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,

Tom
Super User Tom
Super User

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

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 765 views
  • 2 likes
  • 4 in conversation