<?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: Average by Excluding One Observation at a Time in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Average-by-Excluding-One-Observation-at-a-Time/m-p/80982#M23362</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Linlin,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;OK, I retract the words &lt;EM&gt;simple solution&lt;/EM&gt;. For each obs in RETURN, take all obs in RETURN with the same portId and mYear, except the one with the same formId. Take the average for each obs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I guess the best way to understand is to look at the result from&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;proc sql;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;select a.*, b.return as otherReturn&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;from return as a inner join return as b&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;on a.portId = b.portId and a.myear=b.myear and b.firmId ne a.firmId;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;PG&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 01 Oct 2012 01:00:56 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2012-10-01T01:00:56Z</dc:date>
    <item>
      <title>Average by Excluding One Observation at a Time</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Average-by-Excluding-One-Observation-at-a-Time/m-p/80978#M23358</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear Community Members,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a dataset that looks like the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA return;&lt;/P&gt;&lt;P&gt;INPUT portid firmid myear return;&lt;/P&gt;&lt;P&gt;DATALINES;&lt;/P&gt;&lt;P&gt;1 100 200301&amp;nbsp; 2.11&lt;/P&gt;&lt;P&gt;1 120 200301&amp;nbsp; 3.12&lt;/P&gt;&lt;P&gt;1 130 200301&amp;nbsp; 2.13&lt;/P&gt;&lt;P&gt;1 140 200301&amp;nbsp; 3.67&lt;/P&gt;&lt;P&gt;1 100 200302&amp;nbsp; 5.23&lt;/P&gt;&lt;P&gt;1 120 200302&amp;nbsp; 6.81&lt;/P&gt;&lt;P&gt;1 130 200302&amp;nbsp; 2.55&lt;/P&gt;&lt;P&gt;1 140 200302&amp;nbsp; 4.21&lt;/P&gt;&lt;P&gt;1 150 200302&amp;nbsp; 3.21&lt;/P&gt;&lt;P&gt;2 300 200301&amp;nbsp; 1.11&lt;/P&gt;&lt;P&gt;2 320 200301&amp;nbsp; 0.12&lt;/P&gt;&lt;P&gt;2 330 200301 -2.13&lt;/P&gt;&lt;P&gt;2 340 200301 -1.67&lt;/P&gt;&lt;P&gt;2 300 200302&amp;nbsp; 4.23&lt;/P&gt;&lt;P&gt;2 320 200302&amp;nbsp; 3.81&lt;/P&gt;&lt;P&gt;2 330 200302&amp;nbsp; 1.55&lt;/P&gt;&lt;P&gt;2 340 200302&amp;nbsp; 2.21&lt;/P&gt;&lt;P&gt;2 350 200302&amp;nbsp; 4.23&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My objective is to calculate average returns for each portid and myear (i.e. average "return" in each portid-myear pair). Next, match each firmid in a given portid and myear with&amp;nbsp; the corresponding average returns. Normally, I can use "proc means" by "portid myear", but there is a restriction&lt;/P&gt;&lt;P&gt;such that a company's return should be excluded from the corresponding average return. For example,&lt;/P&gt;&lt;P&gt;for portid=1, myear=200301, firmid=100, the corresponding average return=(3.12+2.13+3.67)/3=2.9733333&lt;/P&gt;&lt;P&gt;for portid=1, myear=200301, firmid=120, the corresponding average return=(2.11+2.13+3.67)/3=2.6366666&lt;/P&gt;&lt;P&gt;for portid=2, myear=200302, firmid=350, the corresponding average return=(4.23+3.81+1.55+2.21)/4=2.95&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would really appreciate your help with this problem.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 30 Sep 2012 21:06:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Average-by-Excluding-One-Observation-at-a-Time/m-p/80978#M23358</guid>
      <dc:creator>finans_sas</dc:creator>
      <dc:date>2012-09-30T21:06:39Z</dc:date>
    </item>
    <item>
      <title>Re: Average by Excluding One Observation at a Time</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Average-by-Excluding-One-Observation-at-a-Time/m-p/80979#M23359</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Probably many ways to achieve what you want.&amp;nbsp; E.g.:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc transpose data=return out=need (drop=_name_);&lt;/P&gt;&lt;P&gt;&amp;nbsp; var return;&lt;/P&gt;&lt;P&gt;&amp;nbsp; id firmid;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by portid myear;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data need;&lt;/P&gt;&lt;P&gt;&amp;nbsp; merge return need;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by portid myear;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want (drop=i _:);&lt;/P&gt;&lt;P&gt;&amp;nbsp; set need;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array returns(*) _100--_350;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i=1 to dim(returns);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if input(substr(vname(returns(i)),2),8.) eq firmid then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call missing(returns(i));&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; average=mean(of returns(*));&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 30 Sep 2012 21:42:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Average-by-Excluding-One-Observation-at-a-Time/m-p/80979#M23359</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-09-30T21:42:38Z</dc:date>
    </item>
    <item>
      <title>Re: Average by Excluding One Observation at a Time</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Average-by-Excluding-One-Observation-at-a-Time/m-p/80980#M23360</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There is a simple SQL solution :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;proc sql;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;create table want as&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;select a.*, mean(b.return) as meanEx&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;from return as a inner join return as b&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;on a.portId = b.portId and a.myear=b.myear and b.firmId ne a.firmId&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;group by a.portId, a.mYear, a.firmId, a.return;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;select * from want;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 30 Sep 2012 23:58:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Average-by-Excluding-One-Observation-at-a-Time/m-p/80980#M23360</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2012-09-30T23:58:44Z</dc:date>
    </item>
    <item>
      <title>Re: Average by Excluding One Observation at a Time</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Average-by-Excluding-One-Observation-at-a-Time/m-p/80981#M23361</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi PG,&lt;/P&gt;&lt;P&gt;I don't understand your code. How did you get the average meanEX?&amp;nbsp; Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Oct 2012 00:41:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Average-by-Excluding-One-Observation-at-a-Time/m-p/80981#M23361</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-10-01T00:41:07Z</dc:date>
    </item>
    <item>
      <title>Re: Average by Excluding One Observation at a Time</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Average-by-Excluding-One-Observation-at-a-Time/m-p/80982#M23362</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Linlin,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;OK, I retract the words &lt;EM&gt;simple solution&lt;/EM&gt;. For each obs in RETURN, take all obs in RETURN with the same portId and mYear, except the one with the same formId. Take the average for each obs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I guess the best way to understand is to look at the result from&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;proc sql;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;select a.*, b.return as otherReturn&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;from return as a inner join return as b&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;on a.portId = b.portId and a.myear=b.myear and b.firmId ne a.firmId;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: calibri, verdana, arial, sans-serif; font-size: 12pt;"&gt;PG&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Oct 2012 01:00:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Average-by-Excluding-One-Observation-at-a-Time/m-p/80982#M23362</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2012-10-01T01:00:56Z</dc:date>
    </item>
    <item>
      <title>Re: Average by Excluding One Observation at a Time</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Average-by-Excluding-One-Observation-at-a-Time/m-p/80983#M23363</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you PG&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Oct 2012 01:29:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Average-by-Excluding-One-Observation-at-a-Time/m-p/80983#M23363</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-10-01T01:29:36Z</dc:date>
    </item>
    <item>
      <title>Re: Average by Excluding One Observation at a Time</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Average-by-Excluding-One-Observation-at-a-Time/m-p/80984#M23364</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you so much for your help and clarifying question. These two solutions are really brilliant and practical. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SK&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Oct 2012 02:15:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Average-by-Excluding-One-Observation-at-a-Time/m-p/80984#M23364</guid>
      <dc:creator>finans_sas</dc:creator>
      <dc:date>2012-10-01T02:15:24Z</dc:date>
    </item>
  </channel>
</rss>

