<?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 Calculating Cumulative Percentiles in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculating-Cumulative-Percentiles/m-p/672018#M201882</link>
    <description>&lt;P&gt;I have the following raw data.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	do group="a","b";
		do date=1 to 10;
			x=ranpoi(1,5);
			output;
		end;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;group date x
a      1    3
a      2   10
a      3    4
a      4    3
a      5    8
a      6   10
a      7    5
a      8    5
a      9    2
a     10    2
b      1    7
b      2    5
b      3    7
b      4    2
b      5    9
b      6    4
b      7    4
b      8    6
b      9   10
b     10    3&lt;/PRE&gt;&lt;P&gt;How can I calculate the cumulative percents of the number of dates of X=0,1,...,10 by group? For example,&lt;/P&gt;&lt;PRE&gt;group x  count  cuper
a      0     0    0.0
a      1     0    0.0
a      2     2    0.2
a      3     2    0.4
a      4     1    0.5
a      5     2    0.7
a      6     0    0.7
a      7     0    0.7
a      8     1    0.8
a      9     0    0.8
a     10     2    1.0
b      0     0    0.0
b      1     0    0.0
b      2     1    0.1
b      3     1    0.2
b      4     2    0.4
b      5     1    0.5
b      6     1    0.6
b      7     2    0.8
b      8     0    0.0
b      9     1    1.0
b     10     1    1.0&lt;/PRE&gt;&lt;P&gt;I am already doing the following, but it seems inefficient spending a lot of lines.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table _1 as
		select unique group,x,n(date) as count
		from have
		group by group,x
		order by group,x;
quit;

data _2;
	do group="a","b";
		do x=0 to 10;
			output;
		end;
	end;
run;

proc sql;
	create table _3 as
		select _2.group,_2.x,ifn(count&amp;gt;.,count,0) as count,calculated count/sum(calculated count) as per
		from _2 full join _1 on _2.group=_1.group and _2.x=_1.x
		group by _2.group
		order by group,x;
quit;

data _3;
	set _3;
	by group x;
	if first.group then cuper=0;
	cuper+per;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is there a more efficient solution?&lt;/P&gt;</description>
    <pubDate>Fri, 24 Jul 2020 05:28:07 GMT</pubDate>
    <dc:creator>Junyong</dc:creator>
    <dc:date>2020-07-24T05:28:07Z</dc:date>
    <item>
      <title>Calculating Cumulative Percentiles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-Cumulative-Percentiles/m-p/672018#M201882</link>
      <description>&lt;P&gt;I have the following raw data.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	do group="a","b";
		do date=1 to 10;
			x=ranpoi(1,5);
			output;
		end;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;group date x
a      1    3
a      2   10
a      3    4
a      4    3
a      5    8
a      6   10
a      7    5
a      8    5
a      9    2
a     10    2
b      1    7
b      2    5
b      3    7
b      4    2
b      5    9
b      6    4
b      7    4
b      8    6
b      9   10
b     10    3&lt;/PRE&gt;&lt;P&gt;How can I calculate the cumulative percents of the number of dates of X=0,1,...,10 by group? For example,&lt;/P&gt;&lt;PRE&gt;group x  count  cuper
a      0     0    0.0
a      1     0    0.0
a      2     2    0.2
a      3     2    0.4
a      4     1    0.5
a      5     2    0.7
a      6     0    0.7
a      7     0    0.7
a      8     1    0.8
a      9     0    0.8
a     10     2    1.0
b      0     0    0.0
b      1     0    0.0
b      2     1    0.1
b      3     1    0.2
b      4     2    0.4
b      5     1    0.5
b      6     1    0.6
b      7     2    0.8
b      8     0    0.0
b      9     1    1.0
b     10     1    1.0&lt;/PRE&gt;&lt;P&gt;I am already doing the following, but it seems inefficient spending a lot of lines.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table _1 as
		select unique group,x,n(date) as count
		from have
		group by group,x
		order by group,x;
quit;

data _2;
	do group="a","b";
		do x=0 to 10;
			output;
		end;
	end;
run;

proc sql;
	create table _3 as
		select _2.group,_2.x,ifn(count&amp;gt;.,count,0) as count,calculated count/sum(calculated count) as per
		from _2 full join _1 on _2.group=_1.group and _2.x=_1.x
		group by _2.group
		order by group,x;
quit;

data _3;
	set _3;
	by group x;
	if first.group then cuper=0;
	cuper+per;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is there a more efficient solution?&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jul 2020 05:28:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-Cumulative-Percentiles/m-p/672018#M201882</guid>
      <dc:creator>Junyong</dc:creator>
      <dc:date>2020-07-24T05:28:07Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Cumulative Percentiles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-Cumulative-Percentiles/m-p/672021#M201885</link>
      <description>Proc freq is an alternative to all this code. You get cumulative count and percentage as well &lt;BR /&gt;&lt;A href="https://support.sas.com/resources/papers/proceedings/proceedings/sugi25/25/btu/25p069.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings/proceedings/sugi25/25/btu/25p069.pdf&lt;/A&gt;</description>
      <pubDate>Fri, 24 Jul 2020 05:41:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-Cumulative-Percentiles/m-p/672021#M201885</guid>
      <dc:creator>smantha</dc:creator>
      <dc:date>2020-07-24T05:41:45Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Cumulative Percentiles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-Cumulative-Percentiles/m-p/672022#M201886</link>
      <description>&lt;P&gt;If the data is sorted by group:&lt;/P&gt;
&lt;PRE&gt;proc freq data=  have noprint;
   by group;
   tables date /outcum out=want;
run;&lt;/PRE&gt;
&lt;P&gt;The default output here will also have a cumulative count of date and the percent. You can drop those.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IF you have other variables involved then you could merge this data back on based on group and date.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jul 2020 05:42:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-Cumulative-Percentiles/m-p/672022#M201886</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-07-24T05:42:01Z</dc:date>
    </item>
  </channel>
</rss>

