<?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 many observations within each percentile / proc means in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-many-observations-within-each-percentile-proc-means/m-p/626781#M184901</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm curious about this approach. I got the error below. Trying to fix it but if you already know why i got this error, please let me know.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;369 proc sql;&lt;BR /&gt;370 select STOCK&lt;BR /&gt;371 , min(OPEN) as MIN&lt;BR /&gt;372 , pctl(25,OPEN) as P25&lt;BR /&gt;373 , pctl(50,OPEN) as P50&lt;BR /&gt;374 , pctl(75,OPEN) as P75&lt;BR /&gt;375 , max(OPEN) as MAX&lt;BR /&gt;376 , sum(calculated MIN &amp;lt;= OPEN &amp;lt; calculated P25) as C1&lt;BR /&gt;377 , sum(calculated P25 &amp;lt;= OPEN &amp;lt; calculated P50) as C2&lt;BR /&gt;378 , sum(calculated P50 &amp;lt;= OPEN &amp;lt; calculated P75) as C3&lt;BR /&gt;379 , sum(calculated P75 &amp;lt;= OPEN &amp;lt;=calculated MAX) as C4&lt;BR /&gt;380 FROM sashelp.stocks&lt;BR /&gt;381 group by STOCK;&lt;BR /&gt;ERROR: Summary functions nested in this way are not supported.&lt;BR /&gt;ERROR: Summary functions nested in this way are not supported.&lt;BR /&gt;382 QUIT;&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time&lt;/P&gt;</description>
    <pubDate>Mon, 24 Feb 2020 02:36:59 GMT</pubDate>
    <dc:creator>Cruise</dc:creator>
    <dc:date>2020-02-24T02:36:59Z</dc:date>
    <item>
      <title>How many observations within each percentile / proc means</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-many-observations-within-each-percentile-proc-means/m-p/626772#M184894</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi Folks:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I'm trying to determine how many observations there are within each percentiles. The image below shows my current proc means output and the output that I want that includes the number of observations within each quantiles. Is there a way to accomplish Results Wanted?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PROC MEANS FEB 23.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/36344iE0139B05324AD870/image-size/large?v=v2&amp;amp;px=999" role="button" title="PROC MEANS FEB 23.png" alt="PROC MEANS FEB 23.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC MEANS DATA=sashelp.stocks Q1 MEDIAN Q3 MAX MAXDEC=1;
CLASS STOCK; 
VAR OPEN;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Thank you for your time indeed!&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Best wishes,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Cruise&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2020 01:35:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-many-observations-within-each-percentile-proc-means/m-p/626772#M184894</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2020-02-24T01:35:43Z</dc:date>
    </item>
    <item>
      <title>Re: How many observations within each percentile / proc means</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-many-observations-within-each-percentile-proc-means/m-p/626778#M184898</link>
      <description>&lt;P&gt;Does this work?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  select STOCK
       , min(OPEN)      as MIN
       , pctl(25,OPEN)  as P25
       , pctl(50,OPEN)  as P50
       , pctl(75,OPEN)  as P75
       , max(OPEN)      as MAX
       , sum(calculated MIN &amp;lt;= OPEN &amp;lt; calculated P25) as C1
       , sum(calculated P25 &amp;lt;= OPEN &amp;lt; calculated P50) as C2
       , sum(calculated P50 &amp;lt;= OPEN &amp;lt; calculated P75) as C3
       , sum(calculated P75 &amp;lt;= OPEN &amp;lt;=calculated MAX) as C4
  group by STOCK;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2020 02:20:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-many-observations-within-each-percentile-proc-means/m-p/626778#M184898</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-02-24T02:20:38Z</dc:date>
    </item>
    <item>
      <title>Re: How many observations within each percentile / proc means</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-many-observations-within-each-percentile-proc-means/m-p/626781#M184901</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm curious about this approach. I got the error below. Trying to fix it but if you already know why i got this error, please let me know.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;369 proc sql;&lt;BR /&gt;370 select STOCK&lt;BR /&gt;371 , min(OPEN) as MIN&lt;BR /&gt;372 , pctl(25,OPEN) as P25&lt;BR /&gt;373 , pctl(50,OPEN) as P50&lt;BR /&gt;374 , pctl(75,OPEN) as P75&lt;BR /&gt;375 , max(OPEN) as MAX&lt;BR /&gt;376 , sum(calculated MIN &amp;lt;= OPEN &amp;lt; calculated P25) as C1&lt;BR /&gt;377 , sum(calculated P25 &amp;lt;= OPEN &amp;lt; calculated P50) as C2&lt;BR /&gt;378 , sum(calculated P50 &amp;lt;= OPEN &amp;lt; calculated P75) as C3&lt;BR /&gt;379 , sum(calculated P75 &amp;lt;= OPEN &amp;lt;=calculated MAX) as C4&lt;BR /&gt;380 FROM sashelp.stocks&lt;BR /&gt;381 group by STOCK;&lt;BR /&gt;ERROR: Summary functions nested in this way are not supported.&lt;BR /&gt;ERROR: Summary functions nested in this way are not supported.&lt;BR /&gt;382 QUIT;&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2020 02:36:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-many-observations-within-each-percentile-proc-means/m-p/626781#M184901</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2020-02-24T02:36:59Z</dc:date>
    </item>
    <item>
      <title>Re: How many observations within each percentile / proc means</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-many-observations-within-each-percentile-proc-means/m-p/626784#M184902</link>
      <description>&lt;P&gt;1. Run PROC RANK to create the quartiles/percentiles of interest. The example below does the percentiles in groups of 10.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Run PROC FREQ to see the distributions.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc rank data=sashelp.cars out=cars groups=10;
var mpg_city;
ranks rank_mpg_city;
run;

proc freq data=cars;
table rank_mpg_city;
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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2020 02:42:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-many-observations-within-each-percentile-proc-means/m-p/626784#M184902</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-02-24T02:42:15Z</dc:date>
    </item>
    <item>
      <title>Re: How many observations within each percentile / proc means</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-many-observations-within-each-percentile-proc-means/m-p/626789#M184903</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you Reeza. If I use groups=3&amp;nbsp; in proc rank would it yield 25%, 50% and 75%&amp;nbsp; as shown in the image below?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="proc ranks.png" style="width: 534px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/36345iBDEF0FEBCE427E1F/image-size/large?v=v2&amp;amp;px=999" role="button" title="proc ranks.png" alt="proc ranks.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;proc rank data=sashelp.cars out=cars groups=3;&lt;BR /&gt;var mpg_city;&lt;BR /&gt;ranks rank_mpg_city;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc freq data=cars;&lt;BR /&gt;table rank_mpg_city;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2020 02:54:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-many-observations-within-each-percentile-proc-means/m-p/626789#M184903</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2020-02-24T02:54:43Z</dc:date>
    </item>
    <item>
      <title>Re: How many observations within each percentile / proc means</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-many-observations-within-each-percentile-proc-means/m-p/626790#M184904</link>
      <description>&lt;P&gt;Sorry about this, I don't have SAS handy, so couldn't test.&lt;/P&gt;
&lt;P&gt;Maybe this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  select quartiles.*
       , sum( MIN &amp;lt;= OPEN &amp;lt;  P25) as C1
       , sum( P25 &amp;lt;= OPEN &amp;lt;  P50) as C2
       , sum( P50 &amp;lt;= OPEN &amp;lt;  P75) as C3
       , sum( P75 &amp;lt;= OPEN &amp;lt;= MAX) as C4
  from (select STOCK
             , min(OPEN)      as MIN
             , pctl(25,OPEN)  as P25
             , pctl(50,OPEN)  as P50
             , pctl(75,OPEN)  as P75
             , max(OPEN)      as MAX   
        from SASHELP.STOCKS
        group by STOCK )    quartiles
     , SASHELP.STOCKS       details
  where quartiles.STOCK = details.STOCK      
  group by 1,2,3,4,5,6 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Two (nested) steps now, so probably slower than&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;'s solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise, replacing the &lt;EM&gt;calculated&lt;/EM&gt; values with the calculation itself might work too, though speed may not benefit much either way.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2020 03:03:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-many-observations-within-each-percentile-proc-means/m-p/626790#M184904</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-02-24T03:03:26Z</dc:date>
    </item>
    <item>
      <title>Re: How many observations within each percentile / proc means</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-many-observations-within-each-percentile-proc-means/m-p/626791#M184905</link>
      <description>&lt;P&gt;&lt;EM&gt;Groups=3&lt;/EM&gt;&amp;nbsp; means groups:&amp;nbsp; &amp;nbsp;0-0.333&amp;nbsp; &amp;nbsp; 0.333-0.666&amp;nbsp; &amp;nbsp;0.666-1&lt;/P&gt;
&lt;P&gt;Thirtiles?&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2020 03:05:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-many-observations-within-each-percentile-proc-means/m-p/626791#M184905</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-02-24T03:05:11Z</dc:date>
    </item>
    <item>
      <title>Re: How many observations within each percentile / proc means</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-many-observations-within-each-percentile-proc-means/m-p/626792#M184906</link>
      <description>No, those are actually 4 groups with 3 group dividers. &lt;BR /&gt;0 to 25, 25 to 50, 50 to 75 and 75 to 100. &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;So you'd want GROUPS=4 for quartiles.</description>
      <pubDate>Mon, 24 Feb 2020 03:07:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-many-observations-within-each-percentile-proc-means/m-p/626792#M184906</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-02-24T03:07:10Z</dc:date>
    </item>
    <item>
      <title>Re: How many observations within each percentile / proc means</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-many-observations-within-each-percentile-proc-means/m-p/626793#M184907</link>
      <description>Close, tertiles or turtles if you get caught by autocorrect.</description>
      <pubDate>Mon, 24 Feb 2020 03:08:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-many-observations-within-each-percentile-proc-means/m-p/626793#M184907</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-02-24T03:08:20Z</dc:date>
    </item>
  </channel>
</rss>

