<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: averaging two of three values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483724#M125481</link>
    <description>&lt;P&gt;Yes, I thought about using symput being a silly idea right after I typed it.&lt;/P&gt;
&lt;P&gt;This is a bit better than my previous version (still untested) if one wants to only keep a single step.&lt;/P&gt;
&lt;P&gt;Why &lt;EM&gt;adjust the code somewhat to handle the generation of missing values on the line DIFF=.&lt;/EM&gt; ?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT (keep = W: MEAN ) ;
  set HAVE;                         
  array W[*] W: ; 
  array Z[9999] _temporary_;
  do I = 1 to dim(W) ;   
    Z[I]=W[I]
  end;
  call sortn(of Z[*]);                  
  do I = 9999 to 1 by -1 while (^missing(Z[I-1])) ;          
    DIFF = abs (Z[I] - Z[I-1]) ;    
    if DIFF &amp;lt; MINDIFF then do;
      MINDIFF = DIFF ;                 
      MEAN=mean(Z[I], Z[I-1]) ;                       
    end;                            
  end;                              
run ;  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 03 Aug 2018 10:50:36 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2018-08-03T10:50:36Z</dc:date>
    <item>
      <title>averaging two of three values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483643#M125443</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm new to SAS and this is my first post.&lt;/P&gt;&lt;P&gt;I have a small dataset with body measurements. I have three different measurements for the same variable, and I want to average only two of these values, the closest ones. How do I do this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;My data looks something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;obs weight1 weight2 weight3&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;54 .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;54.7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 53&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; 48 .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;47.5 .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;67.4 .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;68 .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;69&lt;/P&gt;&lt;P&gt;4 .&amp;nbsp; &amp;nbsp; 48 .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 48&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using version 9.4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought I could write a code to compare the sums of weight 1+2, 2+3 and 1+3, and average the smallest quantity, but I don't know how to ask for an absolute value. Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Aug 2018 02:12:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483643#M125443</guid>
      <dc:creator>paolamejia</dc:creator>
      <dc:date>2018-08-03T02:12:32Z</dc:date>
    </item>
    <item>
      <title>Re: averaging two of three values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483644#M125444</link>
      <description>&lt;P&gt;Not able to understand your desired output for the sample. Can you post an output sample for the input sample explaining your requirement plz&lt;/P&gt;</description>
      <pubDate>Fri, 03 Aug 2018 02:18:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483644#M125444</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-03T02:18:25Z</dc:date>
    </item>
    <item>
      <title>Re: averaging two of three values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483662#M125450</link>
      <description>&lt;P&gt;Thanks for replying!&lt;/P&gt;&lt;P&gt;I need to create a new variable that is the average of two of the values, the two closest ones. So where there are only two measurements, the new variable is the average of those two. But if there are three measurements (the third is taken when the discrepancy between the first two is larger than one unit), I want the average to be of only two values, the two closest values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Aug 2018 04:03:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483662#M125450</guid>
      <dc:creator>paolamejia</dc:creator>
      <dc:date>2018-08-03T04:03:34Z</dc:date>
    </item>
    <item>
      <title>Re: averaging two of three values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483663#M125451</link>
      <description>&lt;P&gt;Trying to clarify my question:&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have these data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;obs weight1 weight2 weight3&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;53&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 54.7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 53&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;48&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 47.5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;67.4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 68.5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;69&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; 48&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 48&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output I want is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;obs&amp;nbsp; weight1&amp;nbsp; &amp;nbsp;weight2&amp;nbsp; &amp;nbsp;weight3&amp;nbsp; finalweight&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 53&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 54.7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 53&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 53&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 48&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;47.5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;47.8&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 67.4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 68.5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 69&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;68.8&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 48&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 48&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;48&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Where weight3 is a missing value the new variable is the mean of weight1 and weight2. But when there are three different weights, I only want to use two of them to calculate the mean. Maybe calculating the absolute value of every possible sum of pairs, and&amp;nbsp;then&amp;nbsp;asking SAS to compute the mean of the closest values?&lt;/P&gt;</description>
      <pubDate>Fri, 03 Aug 2018 04:32:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483663#M125451</guid>
      <dc:creator>paolamejia</dc:creator>
      <dc:date>2018-08-03T04:32:14Z</dc:date>
    </item>
    <item>
      <title>Re: averaging two of three values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483664#M125452</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input obs weight1 weight2 weight3 ;
cards;
1     54          54.7        53
2      48          47.5       .  
3     67.4        68          69
4    48          48           .
;

data w;
set have;
n=_n_;
array  t(*) weight:;
k=n(of t(*));
if k=3 then 
do i=1 to 2;
do j=i+1 to 3;
k1=t(i);
k2=t(j);
dif=abs(t(j)-t(i));
output;
end;
end;
else do;avg=mean(weight1,weight2,weight3); output; end;
run;

proc sort data=w out=_w ;
by n  dif;
run;

data want;
set _w;
by n;
if first.n;
if first.n and not last.n then 
avg=mean(k1,k2);
keep n weight: avg;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Aug 2018 04:41:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483664#M125452</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-03T04:41:10Z</dc:date>
    </item>
    <item>
      <title>Re: averaging two of three values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483671#M125459</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT; 
  set HAVE;
  DIFF12=abs(WEIGHT1-WEIGHT2);
  DIFF13=abs(WEIGHT1-WEIGHT3);
  DIFF23=abs(WEIGHT2-WEIGHT3);
  if DIFF12=min(of DIFF:) then AVG=mean(WEIGHT1,WEIGHT2);
  if DIFF13=min(of DIFF:) then AVG=mean(WEIGHT1,WEIGHT3);
  if DIFF23=min(of DIFF:) then AVG=mean(WEIGHT2,WEIGHT3);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Aug 2018 05:14:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483671#M125459</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-08-03T05:14:30Z</dc:date>
    </item>
    <item>
      <title>Re: averaging two of three values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483673#M125461</link>
      <description>&lt;P&gt;Wow, thanks so much! It seems to work great for the observations that have three weight measurements, but what happens with the observations that only have two measurements? They don't seem to come out in the final output, data want, which has only two observations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm going to try it with my own small dataset&lt;/P&gt;</description>
      <pubDate>Fri, 03 Aug 2018 05:17:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483673#M125461</guid>
      <dc:creator>paolamejia</dc:creator>
      <dc:date>2018-08-03T05:17:44Z</dc:date>
    </item>
    <item>
      <title>Re: averaging two of three values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483674#M125462</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/224410"&gt;@paolamejia&lt;/a&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. How are you going to handle the missing values in defining the "closest"? I assume you're ignoring them.&lt;/P&gt;&lt;P&gt;2. How are you going to handle the ties between two or more pairs of values that are equally close? I assume that you pick the first ones from left to right.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your sample data aren't rich enough to test an algorithmic concept. So, try the following input first:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ; &lt;BR /&gt;  call streaminit (7) ; &lt;BR /&gt;  array w weight1-weight5 ; &lt;BR /&gt;  do _n_ = 1 to 5 ; &lt;BR /&gt;    do over w ; &lt;BR /&gt;      w = rand ("integer", 23) ; &lt;BR /&gt;      if rand ("uniform") &amp;lt; .3 then w = . ;&lt;BR /&gt;    end ; &lt;BR /&gt;    output ; &lt;BR /&gt;  end ; &lt;BR /&gt;run ; &lt;BR /&gt;                           &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Now, the program:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (keep = w: mean closest:) ;
  set have ;                         
  array w [*] w: ;                   
  diff = constant ("big") ;          
  do i = 1 to dim (w) - 1 ;          
    if nmiss (w[i]) then continue ;  
    do j = i + 1 to dim (w) ;        
      if nmiss (w[j]) then continue ;
      _diff = abs (w[i] - w[j]) ;    
      if _diff &amp;gt; diff then continue ;
      diff = _diff ;                 
      _i = i ;                       
      _j = j ;                       
    end ;                            
  end ;                              
  closest1 = w[_i] ;                 
  closest2 = w[_j] ;                 
  mean = mean (of closest:) ;        
run ;    &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Note that it's not much different in principle from what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;has offered, save for a couple of generalizations. It generates the following output:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="branch"&gt;&lt;DIV align="left"&gt;weight1 weight2 weight3 weight4 weight5 closest1 closest2 mean &lt;TABLE cellspacing="0" cellpadding="5"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;19&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;22&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;19&lt;/TD&gt;&lt;TD&gt;22&lt;/TD&gt;&lt;TD&gt;20.5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;19&lt;/TD&gt;&lt;TD&gt;21&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;19&lt;/TD&gt;&lt;TD&gt;21&lt;/TD&gt;&lt;TD&gt;20.0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;TD&gt;23&lt;/TD&gt;&lt;TD&gt;11&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;11&lt;/TD&gt;&lt;TD&gt;10.5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;17&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;17&lt;/TD&gt;&lt;TD&gt;10.0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;8.5&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Now that we can see that the concept works, we can move on to your sample data set:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;              
  input weight1-weight3 ;
  obs = _n_ ;            
  cards ;                
54    54.7  53           
48    47.5   .           
67.4  68    69           
  .   48    48           
;                        
run ;                    &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Running the program above against it, we get:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="branch"&gt;&lt;DIV&gt;&lt;DIV align="left"&gt;weight1 weight2 weight3 closest1 closest2 mean &lt;TABLE cellspacing="0" cellpadding="5"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;54.0&lt;/TD&gt;&lt;TD&gt;54.7&lt;/TD&gt;&lt;TD&gt;53&lt;/TD&gt;&lt;TD&gt;54.0&lt;/TD&gt;&lt;TD&gt;54.7&lt;/TD&gt;&lt;TD&gt;54.35&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;48.0&lt;/TD&gt;&lt;TD&gt;47.5&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;48.0&lt;/TD&gt;&lt;TD&gt;47.5&lt;/TD&gt;&lt;TD&gt;47.75&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;67.4&lt;/TD&gt;&lt;TD&gt;68.0&lt;/TD&gt;&lt;TD&gt;69&lt;/TD&gt;&lt;TD&gt;67.4&lt;/TD&gt;&lt;TD&gt;68.0&lt;/TD&gt;&lt;TD&gt;67.70&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;48.0&lt;/TD&gt;&lt;TD&gt;48&lt;/TD&gt;&lt;TD&gt;48.0&lt;/TD&gt;&lt;TD&gt;48.0&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;48.00&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;If you can't discern the idea from the code, it compares each weight to each other pairwise. If the distance between them is shorter than the previously found distance (initially set to an impossibly big number), then the respective array indices are stored, and the process is repeated until the pairing is exhausted. If instead of the very first indices with the same closest distance you want the very last ones, change the inequality sign from &amp;gt; to =&amp;gt;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;HTH&lt;/P&gt;&lt;P&gt;Paul D.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Aug 2018 05:19:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483674#M125462</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2018-08-03T05:19:18Z</dc:date>
    </item>
    <item>
      <title>Re: averaging two of three values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483677#M125464</link>
      <description>&lt;P&gt;Yes! Works like a charm. Thank you so much!&lt;/P&gt;</description>
      <pubDate>Fri, 03 Aug 2018 05:32:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483677#M125464</guid>
      <dc:creator>paolamejia</dc:creator>
      <dc:date>2018-08-03T05:32:39Z</dc:date>
    </item>
    <item>
      <title>Re: averaging two of three values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483680#M125465</link>
      <description>&lt;P&gt;Thank you so much for looking at this. You are right, I'm ignoring the missing values.&lt;/P&gt;&lt;P&gt;What you and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;are proposing is more complex than what I just saw from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;, but the latter seems to work just fine. I don't know what it does when there are ties, my database is really small (153 observations) and I'm only comparing three variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can't discern the idea from the code (yet) but I'll certainly look at those alternatives to get more familiar with SAS. Thanks again!&lt;/P&gt;</description>
      <pubDate>Fri, 03 Aug 2018 05:43:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483680#M125465</guid>
      <dc:creator>paolamejia</dc:creator>
      <dc:date>2018-08-03T05:43:14Z</dc:date>
    </item>
    <item>
      <title>Re: averaging two of three values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483684#M125467</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Tis' nice, especially for handling the ignoring of the nulls.&lt;/P&gt;&lt;P&gt;And terse ... for the number of weights N=3, which certainly fits the scope of the OP's question.&lt;/P&gt;&lt;P&gt;Now, how would you apply/extend this code to N=10? N=100?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best&lt;/P&gt;&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Aug 2018 06:08:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483684#M125467</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2018-08-03T06:08:52Z</dc:date>
    </item>
    <item>
      <title>Re: averaging two of three values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483687#M125468</link>
      <description>&lt;P&gt;If you really want to learn SAS, you have to look beyond the data you have at hand and ask yourself how your code will work and whether it will work when the data change - because it WILL change. Coding for three variables like 12, 13, 23 means putting data (in this case, how many variables you have and what their combinations are for the task at hand) in your program. A properly designed program is only a set of &lt;EM&gt;instructions&lt;/EM&gt; to process data; it shouldn't contain any &lt;EM&gt;data&lt;/EM&gt; itself. That means, in particular:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- No IF-THEN-ELSE "walpaper" code. The hard coded values in the would-be wallpaper should be stored in a table outside the program, and the program should look them up.&lt;/P&gt;&lt;P&gt;- No hard coded constants. These, too, belong to a control file outside the program. The program should read the control file and get the values from it.&lt;/P&gt;&lt;P&gt;- No hard coding relying on a specific dimension, such as the number of variables. The latter, again, belongs to a control file or, much less preferably, macro variables or macro parameters.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any aspiring SAS programmer should dutifully absorb Ian Whitlock's paper "Code or Data?":&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www2.sas.com/proceedings/sugi24/Advtutor/p40-24.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi24/Advtutor/p40-24.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;to understand these issues and also understand that a poor program design may serve one's immediate purpose but bite one in the derriere when it's least expected. I'm eternally grateful to Ian for his savage bluntness on SAS-L of yore when it came to this (and other) kind of matters. There's a saying that a good physicist sees analogies but a great one seen analogies between analogies. With SAS programming, it's no different.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Paul D.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Aug 2018 06:47:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483687#M125468</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2018-08-03T06:47:57Z</dc:date>
    </item>
    <item>
      <title>Re: averaging two of three values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483688#M125469</link>
      <description>&lt;P&gt;Haha! Golf challenge?&lt;/P&gt;
&lt;P&gt;Can't test atm, but something along these lines I suppose (pseudo code made by modifying your code):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT (keep = W: MEAN ) ;
  set HAVE;                         
  array W[*] W: ; 
  call symputx('____dim',dim(W));
  array Z[&amp;amp;____dim.] _temporary_;
  do I = 1 to &amp;amp;____dim.  ;   
    Z[I]=W[I]
  end;
  call sortn(of Z[*]);                  
  do I = 1 to &amp;amp;____dim. - 1 ;          
    DIFF = abs (Z[I] - Z[I+1]) ;    
    if . &amp;lt; DIFF &amp;lt; MINDIFF then do ;
      MINDIFF = DIFF ;                 
      MEAN=mean(Z[I], Z[I+1]) ;                       
    end;                            
  end;                              
run ;  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Would this work?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Aug 2018 06:49:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483688#M125469</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-08-03T06:49:22Z</dc:date>
    </item>
    <item>
      <title>Re: averaging two of three values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483690#M125470</link>
      <description>&lt;P&gt;Ha-ha! Why not. I like your idea, and it should work if further developed. SYMPUTX won't do what you want because it's a run-time instruction, while arrays are sized at compile time, so the value produced by SYMPUTX cannot size an array in the same DATA step. But methinks it will sure work in the context of the following if you adjust the code somewhat to handle the generation of missing values on the line DIFF=.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;                                
  call streaminit (7) ;                    
  array w weight1-weight5 ;                
  do _n_ = 1 to 5 ;                        
    do over w ;                            
      w = rand ("integer", 23) ;           
      if rand ("uniform") &amp;lt; .3 then w = . ;
    end ;                                  
    output ;                               
  end ;                                    
run ;      
                                
%let dim = 5 ;                  
data WANT (keep = W: MEAN ) ;      
  set HAVE;                        
  array W[*] W: ;                  
  array Z[&amp;amp;dim] _temporary_;       
  do I = 1 to &amp;amp;dim  ;              
    Z[I]=W[I] ;                    
  end;                             
  call sortn(of Z[*]);             
  do I = 1 to &amp;amp;dim - 1 ;           
    DIFF = abs (Z[I] - Z[I+1]) ;   
    if . &amp;lt; DIFF &amp;lt; MINDIFF then do ;
      MINDIFF = DIFF ;             
      MEAN=mean(Z[I], Z[I+1]) ;    
    end;                           
  end;                             
run ;  &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Have fun!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best&lt;/P&gt;&lt;P&gt;Paul D.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Aug 2018 07:14:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483690#M125470</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2018-08-03T07:14:58Z</dc:date>
    </item>
    <item>
      <title>Re: averaging two of three values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483724#M125481</link>
      <description>&lt;P&gt;Yes, I thought about using symput being a silly idea right after I typed it.&lt;/P&gt;
&lt;P&gt;This is a bit better than my previous version (still untested) if one wants to only keep a single step.&lt;/P&gt;
&lt;P&gt;Why &lt;EM&gt;adjust the code somewhat to handle the generation of missing values on the line DIFF=.&lt;/EM&gt; ?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT (keep = W: MEAN ) ;
  set HAVE;                         
  array W[*] W: ; 
  array Z[9999] _temporary_;
  do I = 1 to dim(W) ;   
    Z[I]=W[I]
  end;
  call sortn(of Z[*]);                  
  do I = 9999 to 1 by -1 while (^missing(Z[I-1])) ;          
    DIFF = abs (Z[I] - Z[I-1]) ;    
    if DIFF &amp;lt; MINDIFF then do;
      MINDIFF = DIFF ;                 
      MEAN=mean(Z[I], Z[I-1]) ;                       
    end;                            
  end;                              
run ;  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Aug 2018 10:50:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483724#M125481</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-08-03T10:50:36Z</dc:date>
    </item>
    <item>
      <title>Re: averaging two of three values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483781#M125506</link>
      <description>&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;"I'm eternally grateful to Ian for his savage bluntness on SAS-L of yore when it came to this (and other) kind of matters"&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Wow a great person's gesture&amp;nbsp;owards a perhaps "equal" which is so&amp;nbsp;&lt;STRONG&gt; amazing, humble, eloquent,modest and respectful&lt;/STRONG&gt;. I don't know Ian Whitlock, nor i have SAS L account but have heard a lot about him through Art Tabachneck, so guessing.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;That's note a lot of people like me and others should take seriously in all walks of life. That speaks a lot from heart and soul. Thank you!&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The day If and when I become PD. Oh well taking your blessing if even beyond PD, I will echo&amp;nbsp;a similar note to somebody else.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Aug 2018 14:08:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483781#M125506</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-03T14:08:48Z</dc:date>
    </item>
    <item>
      <title>Re: averaging two of three values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483919#M125556</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As I've said, I like your idea - because sorting turns a O(n**2) problem (pairwise comparison) into O(n*log(n)) problem (heap sort behind the scenes). Also, the ordering makes it unnecessary to call the ABS function since you always subtract something smaller or equal. Note, however, that you're not scaling the code you first posted but present an altogether different approach instead. Your new untested code won't work just yet ; but it will with a couple of adjustments:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Since it is a minimum that is being calculated, the initial value should be set to something bigger than any possible MINDIFF. In your code, it is auto-set to missing, which is less than anything but _. and which is why MEAN comes out missing.&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. Since temp array elements are retained, it should be cleaned up for each new record, otherwise the leftovers from the previous records mess up the values relied upon during the calculation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thus, working (and tested) code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT (keep = W: MEAN ) ;                           
  set HAVE ;                                            
  array W [*] W: ;                                      
  array Z [9999] _temporary_;                           
  do I = 1 to dim(W) ;                                  
    Z[I] = W[I] ;                                       
  end;                                                  
  call sortn (of Z[*]) ;                                
  &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;MINDIFF = Z [dim(Z)] ;  &lt;/STRONG&gt; &lt;/FONT&gt;                             
  do I = dim (Z) to 1 by -1 while (^ missing (Z[I-1])) ;
    DIFF = Z[I] - Z[I-1] ; &lt;FONT color="#FF0000"&gt;* Note: no ABS ;&lt;/FONT&gt;                              
    if DIFF &amp;lt; MINDIFF then do ;                          
      MINDIFF = DIFF ;                                  
      MEAN = mean (Z[I], Z[I-1]) ;                      
    end ;                                               
  end ;                                                 
&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;  call missing (of Z{*]) ;      &lt;/STRONG&gt; &lt;/FONT&gt;                       
run ;                                                   &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Of course, performance-wise, sizing the temp array as "big enough" has its impact on sorting. That can be alleviated by using an ordered hash table instead of the temp array, as the former grows and shrinks dynamically. If I find time, I'll post this kind of variant on the theme.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best&lt;/P&gt;&lt;P&gt;Paul D.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;p.s. I said "&lt;EM&gt;adjust the code somewhat to handle the generation of missing values&lt;/EM&gt;" because in my testing, this line generated missing values. Above, it no longer does.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Aug 2018 20:31:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483919#M125556</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2018-08-03T20:31:45Z</dc:date>
    </item>
    <item>
      <title>Re: averaging two of three values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483935#M125558</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As tentatively promised in the earlier reply, here's your sorted list approach encapsulated using a hash table. Note that _N_ below is used merely as a container for W-values in the table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (keep = w: mean ) ;                
  if _n_ = 1 then do ;                       
    dcl hash h (multidata:"Y", ordered:"A") ;
    h.definekey ("_n_") ;                    
    h.definedone () ;                        
    dcl hiter i ("h") ;                      
  end ;                                      
  set have ;                                 
  array w w: ;                               
  do over w ;                                
    if N (w) then h.add(key:w, data:w) ;     
  end ;                                      
  _dm = max (of w:) ;                        
  do _q = 1 by 1 while (i.next() = 0) ;      
    if _q &amp;gt; 1 then do ;                      
      _d = _n_ - _pn ;                       
      if _d &amp;lt; _dm then do ;                  
        _dm = _d ;                           
        mean = mean (_n_, _pn) ;             
      end ;                                  
    end ;                                    
    _pn = _n_ ;                              
  end ;                                      
  h.clear() ;                                
run ;                                        &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I wish, though, that in addition to the hash object we had a simpler linear dynamic structure (sort of like a list in Python). Of course, the hash object can play the role, but a list would provide for simpler and terser coding and less overhead in situations like the case at hand.&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best&lt;/P&gt;&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Aug 2018 22:12:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483935#M125558</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2018-08-03T22:12:59Z</dc:date>
    </item>
    <item>
      <title>Re: averaging two of three values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483981#M125572</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt; Good points.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. In order to get a MEAN even if there is a single value we need to alter the loop slightly so it iterates at least once.&lt;/P&gt;
&lt;P&gt;Taking care of this can also take care of the missing initial value for MINDIFF.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. I thought I didn't need to reset to zero as I refill the array with every observation. But of course and all values go to the end when I sort it, so this was wrong. We just need to fill the back of the array to avoid that then.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So something this may work better (untested):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT (keep = W: MEAN ) ;                           
  set HAVE ;                                            
  array W [*] W: ;                                      
  array Z [9999] _temporary_;                           
  do I = 1 to dim(W) ;                                  
    Z[10000-I] = W[I] ;                                       
  end;                                                  
  call sortn (of Z[*]) ;                                
  do I = 9999 to 2 by -1 until (missing (Z[I-1])) ;&lt;BR /&gt;    DIFF = Z[I] - Z[I-1] ;                              
    if . &amp;lt; DIFF &amp;lt; MINDIFF or MEAN = . then do ;                          
      MINDIFF = DIFF ;                                  
      MEAN = mean (Z[I], Z[I-1]) ;                      
    end ;                                               
  end ;                                
run ;    &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes hash tables require a lot more code, Furthermore:&lt;/P&gt;
&lt;P&gt;3. You needn't have multidata in the hash table.&lt;/P&gt;
&lt;P&gt;4. I wouldn't initialise &lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;_dm &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;max&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;of w:&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;because the logic then fails if the values are negative.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Aug 2018 06:45:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483981#M125572</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-08-04T06:45:53Z</dc:date>
    </item>
    <item>
      <title>Re: averaging two of three values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483986#M125574</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Yes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. Takes care of business. Missing values will still be generated at the DIFF= line, but it's just a matter of log notes. Plus, WHILE (^) instead of UNTIL () can fix that.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3. Yes, I do - if we want the same assumptions. To wit, your code treats ties as "the closest" and computes the mean accordingly. Mine, too, except that I'm getting the lowest ties (since I ascend) and you - the highest (since you descend). This can be aligned on my side if I use ORDERED:"D" (but not on yours, as SORTN always sorts ascending and you run descending for obvious reasons).&amp;nbsp; If I omit MULTIDATA:"Y", there will be no ties; and the result will change accordingly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;4. Agreed;&amp;nbsp; a good catch. Better to set it to constant("big"), as I did initially, to cover all bases.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best&lt;/P&gt;&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Sat, 04 Aug 2018 08:22:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/averaging-two-of-three-values/m-p/483986#M125574</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2018-08-04T08:22:21Z</dc:date>
    </item>
  </channel>
</rss>

