<?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 compute the median of a variable but exclude the observation itself in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-median-of-a-variable-but-exclude-the/m-p/88902#M18912</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In the above datastep,&lt;STRONG&gt; cc&lt;/STRONG&gt; is a variable created automatically by SAS because of the statement&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;if last.decileY then cc + n;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;cc + n; &lt;/STRONG&gt;is a sum statement which creates the accumulator variable &lt;STRONG&gt;cc&lt;/STRONG&gt;. It is equivalent to &lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;retain cc 0;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;cc = sum(cc, n);&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Thus &lt;STRONG&gt;cc&lt;/STRONG&gt; is initialized with zero and it automatically retains its value across datastep iterations.&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;PG&lt;STRONG style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 07 May 2015 15:15:24 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2015-05-07T15:15:24Z</dc:date>
    <item>
      <title>How to compute the median of a variable but exclude the observation itself</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-median-of-a-variable-but-exclude-the/m-p/88894#M18904</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;I'm try to compute the difference between each observation's value of a certain variable (A) and the median of the same variable (A) for&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;its joint industry (X) and performance (Y) decile, where the median excludes the obs itself. I already created deciles for variable Y within each industry X,&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;but can't figure out how to calculate the median of each decile excluding the obs. Any suggestions are much appreciated!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Sep 2013 22:31:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-median-of-a-variable-but-exclude-the/m-p/88894#M18904</guid>
      <dc:creator>navyblue</dc:creator>
      <dc:date>2013-09-19T22:31:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute the median of a variable but exclude the observation itself</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-median-of-a-variable-but-exclude-the/m-p/88895#M18905</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can try this :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;proc sort data=have; by x decileY; run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;create table c as&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;select x, decileY, count(a) as n&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;from have&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;group by x, decileY;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data want;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;merge have c; by x decileY;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;medPos = cc + floor((n+1)/2);&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;if _n_ &amp;lt;= medPos then do;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; medPos = min(cc + n, max(cc + 1, medPos + 1));&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have(keep=a rename=(a=medA)) point=medPos;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;else do;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; medPos = min(cc + n, max(cc + 1, medPos - 1));&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have(keep=a rename=(a=medA)) point=medPos;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;medDif = a - medA;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;if last.decileY then cc + n;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;drop n cc;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The idea is that for observations lower than the true median, your median is the observation just after the true median and for observations greater than the true median, your median is the observation just before the true median.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Sep 2013 02:22:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-median-of-a-variable-but-exclude-the/m-p/88895#M18905</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2013-09-20T02:22:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute the median of a variable but exclude the observation itself</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-median-of-a-variable-but-exclude-the/m-p/88896#M18906</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For each company in a decile/industry group, you want CMED, the "complimentary median" (i.e. median of group members except the company in hand) of variable X.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But of course, you can't directly calculate the CMED the same way you could directly calculate the complimentary mean - after all its a non-parametric measure.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But you are helped by the fact that you're going to get no more than 3 distinct values for CMED over each group.&amp;nbsp; Start out with the MED(X), the "ordinary median" (i.e. including the subject company).&lt;/P&gt;&lt;P&gt;Then all companies with X &amp;lt;&amp;nbsp; MED(X) will have the same CMED (i.e. dropping any of these companies from median calculation is the same as dropping the minimum X).&amp;nbsp; Call this value MEDexMIN(X).&lt;/P&gt;&lt;P&gt;The same principle applies to all companies with X&amp;gt; MED(X).&amp;nbsp; Dropping any of them will produce the same CMED as dropping the maximum X.&amp;nbsp; Call it MEDexMAX(X).&lt;/P&gt;&lt;P&gt;And if the company has X=MED(X)?&amp;nbsp; Then the complimentary median is the mid-point between MEDexMIN(X) and MEDexMAX(X).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note all of these could have the same value if there are a lot of ties at MED(X)..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's a suggested program - I'd consider it a good example of why and how to use the double DOW approach.&amp;nbsp; It assumes your data set HAVE is grouped by decile and industry, and that you have (say) no more than 100 companies in a single decile/industry group:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;data want (drop=_:);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; array _x {100}; /* Establishes variables _x1 ... _x100 */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; do _I = 1 by 1 until (last.industry);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by decile industry nosorted;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _x{_I}=x;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _xmax=max(_xmax,x);&amp;nbsp; if _xmax=x then _imax=_I;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _xmin=min(_xmin,x);&amp;nbsp; if _xmin=x then _imin=_I;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; _med=median(of _x:);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; _x{_Imax}=.;&amp;nbsp; _MEDexMAX=median(of _x:);&amp;nbsp; _x{_imax}=_xmax;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; _x{_imin}=.;&amp;nbsp; _MEDexMIN=median(of _x:);&amp;nbsp; _x{_imin}=_xmin;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; do until (last.industry);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by decile industry notsorted;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if x=. then CMED=.;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else select (sign(x-_med));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; when (1)&amp;nbsp; cmed = MEDexMAX;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; when (-1) cmed = MEDexMIN;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; when (0)&amp;nbsp; cmed = (MEDexMAX+MEDexMIN)/2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Sep 2013 03:19:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-median-of-a-variable-but-exclude-the/m-p/88896#M18906</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2013-09-20T03:19:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute the median of a variable but exclude the observation itself</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-median-of-a-variable-but-exclude-the/m-p/88897#M18907</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you so much for the great help! Your code works perfectly! I'm so impressed by your prompt feedback and glad I find this supportive community. Happy Friday!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Sep 2013 18:21:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-median-of-a-variable-but-exclude-the/m-p/88897#M18907</guid>
      <dc:creator>navyblue</dc:creator>
      <dc:date>2013-09-20T18:21:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute the median of a variable but exclude the observation itself</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-median-of-a-variable-but-exclude-the/m-p/88898#M18908</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you so much for explaining the logic behind the code and providing an alternative solution for my problem. I feel so lucky to get help from you all, this means so much to a beginner. I did try your code but getting error message as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1185&amp;nbsp; data want (drop=_:)&lt;/P&gt;&lt;P&gt;1186&amp;nbsp;&amp;nbsp;&amp;nbsp; array _x (100); /* Establishes variables _x1 ... _x100 */&lt;/P&gt;&lt;P&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ---&lt;/P&gt;&lt;P&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 22&lt;/P&gt;&lt;P&gt;ERROR 22-7: Invalid option name 100.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'll check into this more later when I get a chance. I'm sure your code definitely works perfectly, I just need to find out what I might have typed wrong. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Again, thank you very much!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Sep 2013 18:45:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-median-of-a-variable-but-exclude-the/m-p/88898#M18908</guid>
      <dc:creator>navyblue</dc:creator>
      <dc:date>2013-09-20T18:45:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute the median of a variable but exclude the observation itself</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-median-of-a-variable-but-exclude-the/m-p/88899#M18909</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your DATA statement is missing the semi-colon.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Sep 2013 20:33:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-median-of-a-variable-but-exclude-the/m-p/88899#M18909</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-09-20T20:33:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute the median of a variable but exclude the observation itself</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-median-of-a-variable-but-exclude-the/m-p/88900#M18910</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Good eyes, thanks a lot!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Sep 2013 22:36:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-median-of-a-variable-but-exclude-the/m-p/88900#M18910</guid>
      <dc:creator>navyblue</dc:creator>
      <dc:date>2013-09-24T22:36:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute the median of a variable but exclude the observation itself</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-median-of-a-variable-but-exclude-the/m-p/88901#M18911</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hI&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Refer back to the program listed by PG stats&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;medPos = cc + floor((n+1)/2);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;if _n_ &amp;lt;= medPos then do;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; medPos = min(cc + n, max(cc + 1, medPos + 1));&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have(keep=a rename=(a=medA)) point=medPos;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;else do;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; medPos = min(cc + n, max(cc + 1, medPos - 1));&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have(keep=a rename=(a=medA)) point=medPos;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;medDif = a - medA;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;if last.decileY then cc + n;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;drop n cc;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;What cc stands for, there is no value or definition in the program. Your help is much appreciated. &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Cheers&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;LEE&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 May 2015 01:17:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-median-of-a-variable-but-exclude-the/m-p/88901#M18911</guid>
      <dc:creator>LLCLOUD</dc:creator>
      <dc:date>2015-05-07T01:17:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute the median of a variable but exclude the observation itself</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-median-of-a-variable-but-exclude-the/m-p/88902#M18912</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In the above datastep,&lt;STRONG&gt; cc&lt;/STRONG&gt; is a variable created automatically by SAS because of the statement&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;if last.decileY then cc + n;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;cc + n; &lt;/STRONG&gt;is a sum statement which creates the accumulator variable &lt;STRONG&gt;cc&lt;/STRONG&gt;. It is equivalent to &lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;retain cc 0;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;cc = sum(cc, n);&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Thus &lt;STRONG&gt;cc&lt;/STRONG&gt; is initialized with zero and it automatically retains its value across datastep iterations.&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;PG&lt;STRONG style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 May 2015 15:15:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-median-of-a-variable-but-exclude-the/m-p/88902#M18912</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-05-07T15:15:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute the median of a variable but exclude the observation itself</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-median-of-a-variable-but-exclude-the/m-p/88903#M18913</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi PGStats&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I blindly used the code you posted, it is running ok. however, it doesnot produce MedA further Medif for each observation. There are quite large observations without MedA. I am confused. Your thoughts and help is much appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;li&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 May 2015 00:11:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-median-of-a-variable-but-exclude-the/m-p/88903#M18913</guid>
      <dc:creator>LLCLOUD</dc:creator>
      <dc:date>2015-05-08T00:11:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute the median of a variable but exclude the observation itself</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-median-of-a-variable-but-exclude-the/m-p/88904#M18914</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It might help if your initial sort also includes variable &lt;STRONG&gt;a &lt;/STRONG&gt;:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;proc sort data=have; by x decileY a; run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If that doesn't solve the problem, please provide a small example.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 May 2015 14:59:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-the-median-of-a-variable-but-exclude-the/m-p/88904#M18914</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-05-08T14:59:00Z</dc:date>
    </item>
  </channel>
</rss>

