<?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 Proc Sql Cumulative Percent in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Cumulative-Percent/m-p/300544#M63480</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am using code below -&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table namescnt as select a.*, Count/sum(Count) as pct&lt;BR /&gt;from test a&lt;BR /&gt;group by Gender, Year&lt;BR /&gt;ORDER BY Count Desc;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am wondering if there is a way to calculate the cumulative % (last field in excel) within Proc Sql above for Gender &amp;amp; Year Group. Please see attached excel for example.&lt;/P&gt;</description>
    <pubDate>Sat, 24 Sep 2016 14:42:31 GMT</pubDate>
    <dc:creator>Siddharth123</dc:creator>
    <dc:date>2016-09-24T14:42:31Z</dc:date>
    <item>
      <title>Proc Sql Cumulative Percent</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Cumulative-Percent/m-p/300544#M63480</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am using code below -&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table namescnt as select a.*, Count/sum(Count) as pct&lt;BR /&gt;from test a&lt;BR /&gt;group by Gender, Year&lt;BR /&gt;ORDER BY Count Desc;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am wondering if there is a way to calculate the cumulative % (last field in excel) within Proc Sql above for Gender &amp;amp; Year Group. Please see attached excel for example.&lt;/P&gt;</description>
      <pubDate>Sat, 24 Sep 2016 14:42:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Cumulative-Percent/m-p/300544#M63480</guid>
      <dc:creator>Siddharth123</dc:creator>
      <dc:date>2016-09-24T14:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql Cumulative Percent</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Cumulative-Percent/m-p/300551#M63481</link>
      <description>&lt;P&gt;Not easily.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc freq will report these stats very easily.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Sep 2016 16:38:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Cumulative-Percent/m-p/300551#M63481</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-09-24T16:38:54Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql Cumulative Percent</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Cumulative-Percent/m-p/300565#M63483</link>
      <description>&lt;P&gt;Any processing that requires sequential operations will be easier to do with a datastep :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming dataset &lt;STRONG&gt;test&lt;/STRONG&gt; is properly sorted...&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
do until(last.year);
    set test; by gender year;
    cumCount = sum(cumCount, count);
    end;
cum = 0;
do until(last.year);
    set test; by gender year;
    pct = count / cumCount;
    cum + count;
    cumpct =  cum / cumCount;
    output;
    end;
drop cumCount cum;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 24 Sep 2016 20:59:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Cumulative-Percent/m-p/300565#M63483</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-09-24T20:59:07Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql Cumulative Percent</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Cumulative-Percent/m-p/300584#M63493</link>
      <description>&lt;PRE&gt;
Yeah.That is really not easy. You need create an index variable.

data have;
input gender $ year count;
cards;
F 2011 34
F 2011 34
F 2012 21
F 2012 34
F 2014  4
M 2010  34
M 2011 34
M 2011   45
M 2012  2
M 2012 34
M 2012 34
M 2012 34
;
run;
data have;
 set have;
 by gender;
 if first.gender then n=0;
 n+1;
run;
proc sql;
select a.*,count/sum(count) as per,
 (select sum(count) from have where gender=a.gender and year=a.year and n le a.n)/sum(count) as cumper
from have as a
 group by gender,year
  order by gender,year,n;
quit;



&lt;/PRE&gt;</description>
      <pubDate>Sun, 25 Sep 2016 02:32:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Sql-Cumulative-Percent/m-p/300584#M63493</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-09-25T02:32:54Z</dc:date>
    </item>
  </channel>
</rss>

