<?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: Quartiling and then finding the average in each quartile in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Quartiling-and-then-finding-the-average-in-each-quartile/m-p/323010#M62053</link>
    <description>&lt;P&gt;Use PROC RANK to form the quartiles, as shown in the article &lt;A href="http://blogs.sas.com/content/iml/2012/09/24/grouping-observations-based-on-quantiles.html" target="_self"&gt;"Grouping observations based on quantiles."&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Then use the CLASS statement in &amp;nbsp;PROC MEANS to compute the statistics for each quantile, as shown in this example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let NumGroups = 4;
proc rank data=Sashelp.cars out=Want groups=&amp;amp;NumGroups ties=high;
  var MSRP;     /* variable on which to group */
  ranks Group;  /* name of variable to contain groups 0,1,...,k-1 */
run;

proc format;                  /* display 0-3 as Q1-Q3 */
   value Quartile 0="Q1" 1="Q2" 2="Q3" 3="Q4";
run;

proc means data=Want N MEAN STD;
var MSRP;
class Group;
format group Quartile.;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 06 Jan 2017 15:47:19 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2017-01-06T15:47:19Z</dc:date>
    <item>
      <title>Quartiling and then finding the average in each quartile</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Quartiling-and-then-finding-the-average-in-each-quartile/m-p/323003#M62051</link>
      <description>Hi everyone,&lt;BR /&gt;&lt;BR /&gt;I have a dataset with over 6000 observations. These observations are all rate ie 0.95, 0.83, 0.99 ext. I need to quartile the observations and then find the average rate in each quartile. Essentially I need the average rate in Q1, Q2, Q3, Q4. I tried various procedures and I couldn't do what I wanted. I thought I would ask this community!&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Fri, 06 Jan 2017 15:32:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Quartiling-and-then-finding-the-average-in-each-quartile/m-p/323003#M62051</guid>
      <dc:creator>Yeezus_</dc:creator>
      <dc:date>2017-01-06T15:32:13Z</dc:date>
    </item>
    <item>
      <title>Re: Quartiling and then finding the average in each quartile</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Quartiling-and-then-finding-the-average-in-each-quartile/m-p/323010#M62053</link>
      <description>&lt;P&gt;Use PROC RANK to form the quartiles, as shown in the article &lt;A href="http://blogs.sas.com/content/iml/2012/09/24/grouping-observations-based-on-quantiles.html" target="_self"&gt;"Grouping observations based on quantiles."&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Then use the CLASS statement in &amp;nbsp;PROC MEANS to compute the statistics for each quantile, as shown in this example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let NumGroups = 4;
proc rank data=Sashelp.cars out=Want groups=&amp;amp;NumGroups ties=high;
  var MSRP;     /* variable on which to group */
  ranks Group;  /* name of variable to contain groups 0,1,...,k-1 */
run;

proc format;                  /* display 0-3 as Q1-Q3 */
   value Quartile 0="Q1" 1="Q2" 2="Q3" 3="Q4";
run;

proc means data=Want N MEAN STD;
var MSRP;
class Group;
format group Quartile.;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Jan 2017 15:47:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Quartiling-and-then-finding-the-average-in-each-quartile/m-p/323010#M62053</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-01-06T15:47:19Z</dc:date>
    </item>
    <item>
      <title>Re: Quartiling and then finding the average in each quartile</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Quartiling-and-then-finding-the-average-in-each-quartile/m-p/323015#M62054</link>
      <description>&lt;P&gt;I hope next link will help you:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings10/135-2010.pdf" target="_self"&gt;http://support.sas.com/resources/papers/proceedings10/135-2010.pdf&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jan 2017 15:54:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Quartiling-and-then-finding-the-average-in-each-quartile/m-p/323015#M62054</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-01-06T15:54:53Z</dc:date>
    </item>
    <item>
      <title>Re: Quartiling and then finding the average in each quartile</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Quartiling-and-then-finding-the-average-in-each-quartile/m-p/323020#M62055</link>
      <description>Hey! Thanks for the quick reply. I originally used proc rank and and split the observations into 4 groups. The problem I run into is that there are so many 100% observations that it groups them all together in Q1. For example. If I have 6000 observations, approx 40 percent of them will fall into the first group because they are all 100% rates. That leaves much less observations in Q2.&lt;BR /&gt;&lt;BR /&gt;What I need is to evenly split the observations into equal groups and then quartile it. Basically some of the 100% rates will then fall into Q2, creating equal groups.</description>
      <pubDate>Fri, 06 Jan 2017 16:08:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Quartiling-and-then-finding-the-average-in-each-quartile/m-p/323020#M62055</guid>
      <dc:creator>Yeezus_</dc:creator>
      <dc:date>2017-01-06T16:08:47Z</dc:date>
    </item>
    <item>
      <title>Re: Quartiling and then finding the average in each quartile</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Quartiling-and-then-finding-the-average-in-each-quartile/m-p/323021#M62056</link>
      <description>&lt;P&gt;How do you know which ones go to which group? At that rate how is it different than random? You definitely can't call it quartiles...&lt;/P&gt;
&lt;P&gt;EDIT: My mistake, it won't matter since thats the group you're summarizing. But don't call it quartiles, that would be misleading.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sashelp.cars out=cars;
by mpg_highway;
run;

data check; 
set cars nobs=num;

n_group=floor(_n_/(num/4));
if n_group=4 then n_group=3; *reassign last obs;
run;

proc means data=check;
class n_group;
var mpg_highway;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jan 2017 16:17:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Quartiling-and-then-finding-the-average-in-each-quartile/m-p/323021#M62056</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-01-06T16:17:35Z</dc:date>
    </item>
    <item>
      <title>Re: Quartiling and then finding the average in each quartile</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Quartiling-and-then-finding-the-average-in-each-quartile/m-p/323034#M62060</link>
      <description>&lt;P&gt;Yes, unfortunately this problem can occur. &amp;nbsp;See the article &lt;A href="http://blogs.sas.com/content/iml/2014/11/05/binning-quantiles-rounded-data.html" target="_self"&gt;"Binning data by quantiles? Beware of rounded data."&lt;/A&gt;&amp;nbsp;The article says that is there are N observations and k groups then "if there are more than &lt;EM&gt;N/k&lt;/EM&gt; repeated values, the repeated value can occupy more than one quantile value. In fact, this will &lt;EM&gt;always&lt;/EM&gt; happen if a particular value is repeated more than 2&lt;EM&gt;N/k&lt;/EM&gt; times."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The article concludes with this warning: "Beware of using quantiles to bin rounded data into groups. Although the technique works great when almost all of the data values are distinct, you can run into problems if you ask for many bins and your data contain many repeated values."&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jan 2017 16:34:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Quartiling-and-then-finding-the-average-in-each-quartile/m-p/323034#M62060</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-01-06T16:34:58Z</dc:date>
    </item>
    <item>
      <title>Re: Quartiling and then finding the average in each quartile</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Quartiling-and-then-finding-the-average-in-each-quartile/m-p/323041#M62062</link>
      <description>Hey, I am going go try this now. Just to clarify, what does the _n_ refer to below?&lt;BR /&gt;&lt;BR /&gt;n_group=floor(_n_/(num/4));&lt;BR /&gt;if n_group=4 then n_group=3; *reassign last obs;&lt;BR /&gt;run;&lt;BR /&gt;</description>
      <pubDate>Fri, 06 Jan 2017 16:50:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Quartiling-and-then-finding-the-average-in-each-quartile/m-p/323041#M62062</guid>
      <dc:creator>Yeezus_</dc:creator>
      <dc:date>2017-01-06T16:50:36Z</dc:date>
    </item>
    <item>
      <title>Re: Quartiling and then finding the average in each quartile</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Quartiling-and-then-finding-the-average-in-each-quartile/m-p/323043#M62063</link>
      <description>&lt;P&gt;_n_ is a pseudo row number, that I'm using as a row number. It's an automatic variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/69852/HTML/default/viewer.htm#p0e0mk25gs9binn1s9jiu4otau29.htm&amp;nbsp;" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/69852/HTML/default/viewer.htm#p0e0mk25gs9binn1s9jiu4otau29.htm&amp;nbsp;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jan 2017 16:55:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Quartiling-and-then-finding-the-average-in-each-quartile/m-p/323043#M62063</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-01-06T16:55:35Z</dc:date>
    </item>
    <item>
      <title>Re: Quartiling and then finding the average in each quartile</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Quartiling-and-then-finding-the-average-in-each-quartile/m-p/323138#M62068</link>
      <description>&lt;P&gt;If you want your ties to be randomly split between quartiles, use small random tie breakers:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cars;
set sashelp.cars;
/* Add random noise smaller than data precision */
qtr_mpg_highway = mpg_highway + 0.00001*rand("uniform");
run;

proc rank data=cars out=check groups=4;
var qtr_mpg_highway; 
run;

proc means data=check;
class qtr_mpg_highway;
var mpg_highway;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 07 Jan 2017 02:58:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Quartiling-and-then-finding-the-average-in-each-quartile/m-p/323138#M62068</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-01-07T02:58:43Z</dc:date>
    </item>
    <item>
      <title>Re: Quartiling and then finding the average in each quartile</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Quartiling-and-then-finding-the-average-in-each-quartile/m-p/468788#M70770</link>
      <description>&lt;P&gt;Your code is helpful.&amp;nbsp;why are you reassigning the last observation?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jun 2018 16:47:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Quartiling-and-then-finding-the-average-in-each-quartile/m-p/468788#M70770</guid>
      <dc:creator>pmpradhan</dc:creator>
      <dc:date>2018-06-08T16:47:13Z</dc:date>
    </item>
  </channel>
</rss>

