<?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: quartiles in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/quartiles/m-p/720863#M223343</link>
    <description>&lt;P&gt;As far as I understand Rick's IML code, the calculation can be done in a DATA step as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data quartiles(keep=_q1-_q3);
array _v[9999] _temporary_; /* use dimension &amp;gt;= number of non-missing obs. in dataset T1 */
do _n=1 by 1 until(last);
  set t1(where=(n(value))) end=last;
  _v[_n]=value;
end;
array _q[3];
do _k=1 to 3;
  _p=_k/4;
  _j=floor(_n*_p + 1-_p);
  _g=_n*_p + 1-_p - _j;
  _q[_k]=(1-_g)*smallest(_j, of _v[*]) + _g*smallest(_j+1, of _v[*]);
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This code calculates the first, second and third quartile (&lt;FONT face="courier new,courier"&gt;_q1&lt;/FONT&gt;, &lt;FONT face="courier new,courier"&gt;_q2&lt;/FONT&gt;, &lt;FONT face="courier new,courier"&gt;_q3&lt;/FONT&gt;) of the values in dataset T1 (variable VALUE) using "Definition 7," provided that &amp;lt;=9999 values are involved (otherwise increase the array dimension).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At least for your sample data the result matches the values computed by Excel 2013:&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="4"&gt;_q1    _q2     _q3

3.5    7.5    9.25&lt;/FONT&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 22 Feb 2021 10:41:18 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2021-02-22T10:41:18Z</dc:date>
    <item>
      <title>quartiles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quartiles/m-p/720525#M223206</link>
      <description>&lt;P&gt;with the following code I calculate the first quartile of a data set. in the example with sas the first quartile is 3, but in excel it is calculated at 3.5, why?&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 t1;
input value;
datalines;
1
2
4
7
8
9
10
12
;
PROC MEANS data=t1 q1 ;
VAR value;
RUN;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In excel&amp;nbsp;the result of the following formula is 3.5 instead:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;=QUARTILE(A2:A9;1)&lt;/P&gt;
&lt;P&gt;where A2: A9 are in excel the same data of the example in sas&lt;/P&gt;</description>
      <pubDate>Fri, 19 Feb 2021 17:46:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quartiles/m-p/720525#M223206</guid>
      <dc:creator>mariopellegrini</dc:creator>
      <dc:date>2021-02-19T17:46:05Z</dc:date>
    </item>
    <item>
      <title>Re: quartiles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quartiles/m-p/720527#M223208</link>
      <description>&lt;P&gt;There isn't a single standard definition of quartiles and Excel actually uses an approximation method. Proc means has&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=proc&amp;amp;docsetTarget=n1qnc9bddfvhzqn105kqitnf29cp.htm&amp;amp;locale=en#n1xsk6v7ixfsrmn1phcsrgps47mi" target="_self"&gt; 5 different definitions&lt;/A&gt; you can use and specify on the PROC MEANS statement. &lt;BR /&gt;&lt;BR /&gt;I personally, would not consider Excel statistics to be accurate in comparison to a statistical tool, like SAS, R or Python. &lt;BR /&gt;&lt;BR /&gt;The manual, naive calculation for your example generates a 3. &lt;BR /&gt;&lt;BR /&gt;2 + 4 / 2 = 3. &lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/3574"&gt;@mariopellegrini&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;with the following code I calculate the first quartile of a data set. in the example with sas the first quartile is 3, but in excel it is calculated at 3.5, why?&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 t1;
input value;
datalines;
1
2
4
7
8
9
10
12
;
PROC MEANS data=t1 q1 ;
VAR value;
RUN;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In excel&amp;nbsp;the result of the following formula is 3.5 instead:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;=QUARTILE(A2:A9;1)&lt;/P&gt;
&lt;P&gt;where A2: A9 are in excel the same data of the example in sas&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Feb 2021 17:59:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quartiles/m-p/720527#M223208</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-02-19T17:59:51Z</dc:date>
    </item>
    <item>
      <title>Re: quartiles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quartiles/m-p/720529#M223210</link>
      <description>&lt;P&gt;You may want to read the Proc Means documentation calculation of quantiles.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=proc&amp;amp;docsetTarget=n1w9gy2i68y18an1tfy0asmpbf0g.htm&amp;amp;locale=en" target="_blank"&gt;https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=proc&amp;amp;docsetTarget=n1w9gy2i68y18an1tfy0asmpbf0g.htm&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically there are different definitions possible for quantile, mostly involving differences in how the value for a "not actually encounter quantile" is treated. So Excel and the defaults of SAS are using different methods to calculate the value between 2 and 4 in your data.&lt;/P&gt;
&lt;P&gt;Some approaches could result in 2 or 4 as values that actually occur in your data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Feb 2021 18:02:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quartiles/m-p/720529#M223210</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-02-19T18:02:06Z</dc:date>
    </item>
    <item>
      <title>Re: quartiles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quartiles/m-p/720555#M223215</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/3574"&gt;@mariopellegrini&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The article "&lt;A href="https://blogs.sas.com/content/iml/2017/05/24/definitions-sample-quantiles.html" target="_blank" rel="noopener"&gt;Sample quantiles: A comparison of 9 definitions&lt;/A&gt;" in Rick Wicklin's blog reviews not only the five sample quantile definitions implemented in SAS (see option &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=proc&amp;amp;docsetTarget=n1qnc9bddfvhzqn105kqitnf29cp.htm&amp;amp;locale=en#n1xsk6v7ixfsrmn1phcsrgps47mi" target="_blank" rel="noopener"&gt;QNTLDEF=&lt;/A&gt; in the PROC MEANS documentation), but also four additional definitions described in a 1996 journal article. Your example and a few others that I've quickly checked suggest that Excel's QUARTILE function uses one of those additional definitions: "definition 7" in the journal, "type=7" in Rick's blog and SAS/IML code, which you could use to compute the quartiles based on that definition. (I couldn't test it because SAS/IML is not included in my SAS license).&lt;/P&gt;</description>
      <pubDate>Fri, 19 Feb 2021 19:44:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quartiles/m-p/720555#M223215</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-02-19T19:44:11Z</dc:date>
    </item>
    <item>
      <title>Re: quartiles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quartiles/m-p/720857#M223341</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;A class="trigger-hovercard" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733" target="_blank"&gt;&lt;FONT&gt;FreelanceReinhard&lt;/FONT&gt;&lt;/A&gt;&lt;FONT&gt;, but I don't understand how to do the calculation for example for the sample of my example using the "type = 7"&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Feb 2021 08:43:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quartiles/m-p/720857#M223341</guid>
      <dc:creator>mariopellegrini</dc:creator>
      <dc:date>2021-02-22T08:43:54Z</dc:date>
    </item>
    <item>
      <title>Re: quartiles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/quartiles/m-p/720863#M223343</link>
      <description>&lt;P&gt;As far as I understand Rick's IML code, the calculation can be done in a DATA step as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data quartiles(keep=_q1-_q3);
array _v[9999] _temporary_; /* use dimension &amp;gt;= number of non-missing obs. in dataset T1 */
do _n=1 by 1 until(last);
  set t1(where=(n(value))) end=last;
  _v[_n]=value;
end;
array _q[3];
do _k=1 to 3;
  _p=_k/4;
  _j=floor(_n*_p + 1-_p);
  _g=_n*_p + 1-_p - _j;
  _q[_k]=(1-_g)*smallest(_j, of _v[*]) + _g*smallest(_j+1, of _v[*]);
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This code calculates the first, second and third quartile (&lt;FONT face="courier new,courier"&gt;_q1&lt;/FONT&gt;, &lt;FONT face="courier new,courier"&gt;_q2&lt;/FONT&gt;, &lt;FONT face="courier new,courier"&gt;_q3&lt;/FONT&gt;) of the values in dataset T1 (variable VALUE) using "Definition 7," provided that &amp;lt;=9999 values are involved (otherwise increase the array dimension).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At least for your sample data the result matches the values computed by Excel 2013:&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="4"&gt;_q1    _q2     _q3

3.5    7.5    9.25&lt;/FONT&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 22 Feb 2021 10:41:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/quartiles/m-p/720863#M223343</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-02-22T10:41:18Z</dc:date>
    </item>
  </channel>
</rss>

