<?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: How to calculate average within column from position change in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-average-within-column-from-position-change/m-p/868009#M342833</link>
    <description>&lt;P&gt;Please let me know if this needs further explanation . Thank you !&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 04 Apr 2023 15:34:20 GMT</pubDate>
    <dc:creator>monikka1991</dc:creator>
    <dc:date>2023-04-04T15:34:20Z</dc:date>
    <item>
      <title>How to calculate average within column from position change</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-average-within-column-from-position-change/m-p/868001#M342829</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to calculate the average with the Column . I was doing it in excel and want this to be converted to SAS programming .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On example below ,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are each month , the data feeds and I am trying to calculate the average with the Fifth load .&lt;/P&gt;
&lt;P&gt;Avg_1 :&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF6600"&gt;Calculate average difference between the first loaded data vs fifth time loaded value for Mon1&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF6600"&gt;Calculate average difference between the first loaded data vs fifth time loaded value for Mon2&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Avg_2 :&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000FF"&gt;Calculate average difference between the second time loaded data vs fifth time loaded value for Mon1&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000FF"&gt;Calculate average difference between the second time loaded data vs fifth time loaded value for Mon2&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Avg_3 :&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#99CC00"&gt;Calculate average difference between the third time loaded data vs fifth time loaded value for Mon1&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#99CC00"&gt;Calculate average difference between the third&amp;nbsp; time loaded data vs fifth time loaded value for Mon2&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Avg_4 :&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF00FF"&gt;Calculate average difference between the fourth time loaded data vs fifth time loaded value for Mon1&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF00FF"&gt;Calculate average difference between the fourth time loaded data vs fifth time loaded value for Mon2&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;then once it reaches the fifth time load, it has to exit , further no need of calc averages.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can someone help me to get in SAS loop to done ?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="447"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="148.641px" height="30px"&gt;HAVE&lt;/TD&gt;
&lt;TD width="164.734px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="132.625px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="148.641px" height="30px"&gt;S.No&lt;/TD&gt;
&lt;TD width="164.734px" height="30px"&gt;&lt;STRONG&gt;Mon1&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="132.625px" height="30px"&gt;&lt;STRONG&gt;Mon2&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="148.641px" height="30px"&gt;10&lt;/TD&gt;
&lt;TD width="164.734px" height="30px"&gt;1815&lt;/TD&gt;
&lt;TD width="132.625px" height="30px"&gt;1456&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="148.641px" height="30px"&gt;9&lt;/TD&gt;
&lt;TD width="164.734px" height="30px"&gt;1770&lt;/TD&gt;
&lt;TD width="132.625px" height="30px"&gt;1428&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="148.641px" height="30px"&gt;8&lt;/TD&gt;
&lt;TD width="164.734px" height="30px"&gt;1773&lt;/TD&gt;
&lt;TD width="132.625px" height="30px"&gt;1432&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="148.641px" height="30px"&gt;7&lt;/TD&gt;
&lt;TD width="164.734px" height="30px"&gt;1770&lt;/TD&gt;
&lt;TD width="132.625px" height="30px"&gt;1429&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="148.641px" height="30px"&gt;6&lt;/TD&gt;
&lt;TD width="164.734px" height="30px"&gt;&lt;FONT color="#993366"&gt;&lt;U&gt;&lt;STRONG&gt;1747&lt;/STRONG&gt;&lt;/U&gt;&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="132.625px" height="30px"&gt;1412&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="148.641px" height="30px"&gt;5&lt;/TD&gt;
&lt;TD width="164.734px" height="30px"&gt;&lt;FONT color="#FF00FF"&gt;1773&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="132.625px" height="30px"&gt;&lt;FONT color="#993366"&gt;&lt;U&gt;&lt;STRONG&gt;1419&lt;/STRONG&gt;&lt;/U&gt;&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="148.641px" height="30px"&gt;4&lt;/TD&gt;
&lt;TD width="164.734px" height="30px"&gt;&lt;FONT color="#99CC00"&gt;2136&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="132.625px" height="30px"&gt;&lt;FONT color="#FF00FF"&gt;1427&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="148.641px" height="30px"&gt;3&lt;/TD&gt;
&lt;TD width="164.734px" height="30px"&gt;&lt;FONT color="#0000FF"&gt;2289&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="132.625px" height="30px"&gt;&lt;FONT color="#339966"&gt;1798&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="148.641px" height="30px"&gt;2&lt;/TD&gt;
&lt;TD width="164.734px" height="30px"&gt;&lt;FONT color="#FF6600"&gt;1943&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="132.625px" height="30px"&gt;&lt;FONT color="#0000FF"&gt;1875&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="148.641px" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="164.734px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="132.625px" height="30px"&gt;&lt;FONT color="#FF6600"&gt;1520&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="148.641px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="164.734px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="132.625px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="148.641px" height="30px"&gt;OUTPUT&lt;/TD&gt;
&lt;TD width="164.734px" height="30px"&gt;&lt;STRONG&gt;Mon1&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="132.625px" height="30px"&gt;&lt;STRONG&gt;Mon2&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD rowspan="2" width="148.641px" height="66px"&gt;Avg_1&lt;/TD&gt;
&lt;TD width="164.734px" height="36px"&gt;&lt;FONT color="#FF6600"&gt;-11%&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="132.625px" height="36px"&gt;&lt;FONT color="#FF6600"&gt;-7%&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="164.734px" height="30px"&gt;(1-(&lt;FONT color="#993366"&gt;&lt;STRONG&gt;1747&lt;/STRONG&gt;&lt;/FONT&gt;/&lt;FONT color="#FF6600"&gt;1943&lt;/FONT&gt;))&amp;nbsp;&lt;/TD&gt;
&lt;TD width="132.625px" height="30px"&gt;(1-(&lt;FONT color="#993366"&gt;&lt;STRONG&gt;1419&lt;/STRONG&gt;&lt;/FONT&gt;/&lt;FONT color="#FF6600"&gt;1520&lt;/FONT&gt;))&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD rowspan="2" width="148.641px" height="60px"&gt;Avg_2&lt;/TD&gt;
&lt;TD width="164.734px" height="30px"&gt;&lt;FONT color="#0000FF"&gt;-31%&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="132.625px" height="30px"&gt;&lt;FONT color="#0000FF"&gt;-33%&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="164.734px" height="30px"&gt;(1-(&lt;FONT color="#993366"&gt;&lt;STRONG&gt;1747&lt;/STRONG&gt;&lt;/FONT&gt;/&lt;FONT color="#0000FF"&gt;2289&lt;/FONT&gt;))&lt;/TD&gt;
&lt;TD width="132.625px" height="30px"&gt;(1-(&lt;FONT color="#993366"&gt;&lt;STRONG&gt;1419&lt;/STRONG&gt;&lt;/FONT&gt;/&lt;FONT color="#0000FF"&gt;1875&lt;/FONT&gt;))&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD rowspan="2" width="148.641px" height="60px"&gt;Avg_3&lt;/TD&gt;
&lt;TD width="164.734px" height="30px"&gt;&lt;FONT color="#99CC00"&gt;-22%&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="132.625px" height="30px"&gt;&lt;FONT color="#99CC00"&gt;-27%&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="164.734px" height="30px"&gt;(1-(&lt;FONT color="#993366"&gt;&lt;STRONG&gt;1747&lt;/STRONG&gt;&lt;/FONT&gt;/&lt;FONT color="#99CC00"&gt;2136&lt;/FONT&gt;))&lt;/TD&gt;
&lt;TD width="132.625px" height="30px"&gt;(1-(&lt;FONT color="#993366"&gt;&lt;STRONG&gt;1419&lt;/STRONG&gt;&lt;/FONT&gt;/&lt;FONT color="#99CC00"&gt;1798&lt;/FONT&gt;))&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="148.641px" height="30px"&gt;Avg_4&lt;/TD&gt;
&lt;TD width="164.734px" height="30px"&gt;&lt;FONT color="#FF00FF"&gt;-1%&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="132.625px" height="30px"&gt;&lt;FONT color="#FF00FF"&gt;-1%&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="148.641px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="164.734px" height="30px"&gt;(1-(&lt;STRONG&gt;&lt;FONT color="#993366"&gt;1747&lt;/FONT&gt;&lt;/STRONG&gt;/&lt;FONT color="#FF00FF"&gt;1773&lt;/FONT&gt;))&lt;/TD&gt;
&lt;TD width="132.625px" height="30px"&gt;(1-(&lt;STRONG&gt;&lt;FONT color="#993366"&gt;1419&lt;/FONT&gt;&lt;/STRONG&gt;/&lt;FONT color="#FF00FF"&gt;1427&lt;/FONT&gt;))&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Tue, 04 Apr 2023 15:14:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-average-within-column-from-position-change/m-p/868001#M342829</guid>
      <dc:creator>monikka1991</dc:creator>
      <dc:date>2023-04-04T15:14:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate average within column from position change</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-average-within-column-from-position-change/m-p/868009#M342833</link>
      <description>&lt;P&gt;Please let me know if this needs further explanation . Thank you !&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2023 15:34:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-average-within-column-from-position-change/m-p/868009#M342833</guid>
      <dc:creator>monikka1991</dc:creator>
      <dc:date>2023-04-04T15:34:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate average within column from position change</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-average-within-column-from-position-change/m-p/868012#M342834</link>
      <description>&lt;P&gt;What is a "fifth time loaded" and exactly how to do we tell what it is from the values in the data set?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It may help to show the results in terms of NEW variables added to the data instead of attempting to replace them as the replacement has a very good chance of messing with what you are calculating for some values of "xth time loaded".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are there ever more or fewer than 10 rows of data? Does the actual value of the S. No have any role in the calculations?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2023 15:48:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-average-within-column-from-position-change/m-p/868012#M342834</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-04-04T15:48:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate average within column from position change</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-average-within-column-from-position-change/m-p/868032#M342845</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="3"&gt;Thanks for the response !&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;What is a "fifth time loaded" and exactly how to do we tell what it is from the values in the data set?&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&amp;gt; Incase of Mon1, the fifth value is&amp;nbsp;&lt;STRONG&gt;1747&lt;/STRONG&gt; which is fifth from the bottom to top&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&amp;gt; Incase of Mon2,&amp;nbsp; the fifth value is &lt;STRONG&gt;1419&lt;/STRONG&gt; which is&amp;nbsp;fifth from the bottom to top&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&amp;gt; It would change for the next month&amp;nbsp; , to a row up again. It follows the sequence from bottom to top on the fifth entered value .&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;It may help to show the results in terms of NEW variables added to the data instead of attempting to replace them as the replacement has a very good chance of messing with what you are calculating for some values of "xth time loaded".&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;gt; &lt;FONT size="2"&gt;yeh even as a separate&amp;nbsp;output dataset which have calc average from 5 vs 4, 5 vs 3 , 5 vs 2 and 5 vs 1 would be fine&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;Are there ever more or fewer than 10 rows of data? Does the actual value of the S. No have any role in the calculations?&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;Its not always 10 rows of data, in the mon1 , there is only 9 rows has the value&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;I have added the S.No here , you can add, or remove any intermediate column if we want to .&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;I have done the shared output calculation in excel basically , for some of the modelling techniques, I am trying to do the math from SAS&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2023 17:05:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-average-within-column-from-position-change/m-p/868032#M342845</guid>
      <dc:creator>monikka1991</dc:creator>
      <dc:date>2023-04-04T17:05:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate average within column from position change</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-average-within-column-from-position-change/m-p/868034#M342847</link>
      <description>&lt;P&gt;The idea of doing something in Excel, and then trying to do the same thing in SAS, usually is a difficult one. Excel and SAS work fundamentally differently, and so the layout you have in Excel (which works well in Excel) is a pretty poor layout for doing things in SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will just have to get used to this, for some things doing it in SAS the same way as you did it in Excel is going to be difficult.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's a lot easier if you could turn the data on its side in SAS, or even leave it in columns but reverse the order so that S. No = 1 is at the top of the data set and not at the bottom.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, do you want to go that way in SAS?&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2023 17:11:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-average-within-column-from-position-change/m-p/868034#M342847</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-04T17:11:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate average within column from position change</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-average-within-column-from-position-change/m-p/868036#M342849</link>
      <description>&lt;P&gt;yes PaigeMiller. I need not to maintain same order as I showed. If this needs to be rearrange and get the calc average is also works for me&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2023 17:17:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-average-within-column-from-position-change/m-p/868036#M342849</guid>
      <dc:creator>monikka1991</dc:creator>
      <dc:date>2023-04-04T17:17:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate average within column from position change</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-average-within-column-from-position-change/m-p/868037#M342850</link>
      <description>&lt;P&gt;UNTESTED CODE because I can't write code to work with your screen capture of the data&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
    by sno;
run;
data want;
    set have;
    if not missing then count1+1;
    if not missing then count2+1;
    mon1_1=lag(mon1);
    mon1_2=lag2(mon1);
    mon1_3=lag3(mon1);
    mon1_4=lag4(mon1);
    mon2_1=lag(mon2);
    mon2_2=lag2(mon2);
    mon2_3=lag3(mon2);
    mon2_4=lag4(mon2);
    if count1=5 then do;
        mon1_avg1=1-(mon1/mon1_4);
        mon2_avg2=1-(mon1/mon1_3);
        mon1_avg3=1-(mon1/mon1_2);
        mon1_avg4=1-(mon1/mon1_1);
     end;
     if count2=5 then do;
         mon2_avg1=1-(mon2/mon2_4);
         /* I'm lazy, you type the rest */
     end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I challenge you to think of a better way to design this problem and design this analysis in the future, that will work better within SAS. Excel thinking doesn't help when you are working in SAS.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2023 17:34:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-average-within-column-from-position-change/m-p/868037#M342850</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-04T17:34:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate average within column from position change</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-average-within-column-from-position-change/m-p/868045#M342854</link>
      <description>&lt;P&gt;Here is a solution, but maybe not the best solution. However, it fulfills your request.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data want;
length stat $5;
set have;
array mon[*] mon:;
array m[7,2] _temporary_;

* correct for the misalignment of data;
if not missing(mon1) then do;
    i1 + 1;
    m[i1,1] = mon1;
end;
if not missing(mon2) then do;
    i2 + 1;
    m[i2,2] = mon2;
end;

* after collecting 5 full months data for each month, compute changes;
if min(i1, i2) = 5 then do;
    do i = 1 to 4;
        do j = 1 to 2;
            stat = cats('avg_',i);
            mon[j] = 1 - m[i,j]/m[5,j];
        end;
    output;
    end;
    stop;
end;
format mon: percentn8.0;
keep stat mon:;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Result:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;stat	Mon1	Mon2
avg_1	-11%	-7%
avg_2	-31%	-32%
avg_3	-22%	-27%
avg_4	-1%	-1%&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Here's the prep steps to get the data in the right order.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data have;
infile cards dlm='09'x dsd;
input SNo	Mon1	Mon2;
cards;
10	1815	1456
9	1770	1428
8	1773	1432
7	1770	1429
6	1747	1412
5	1773	1419
4	2136	1427
3	2289	1798
2	1943	1875
1	.	1520
;
run;

proc sort;
by SNo;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Apr 2023 18:29:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-average-within-column-from-position-change/m-p/868045#M342854</guid>
      <dc:creator>FloydNevseta</dc:creator>
      <dc:date>2023-04-04T18:29:35Z</dc:date>
    </item>
  </channel>
</rss>

