<?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: PROC REPORT calculate percent in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-REPORT-calculate-percent/m-p/958773#M374176</link>
    <description>&lt;P&gt;Define both z1 and z2 as group, calculate sums for groups defined by z1, and the compute the percentages:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input z1 $ z2 x w;
cards; 
A 1 10 20
A 2 20 30
A 3 40 50
B 1 15 30
B 2 25 30
B 3 40 50
;

proc report data=have;
column z1 z2 x pct_x w pct_w;
define z1 / group;
define z2 / group;
define x / analysis;
define pct_x / computed format=percent8.2;
define w / analysis;
define pct_w / computed format=percent8.2;
compute before z1;
  x_sum = x.sum;
  w_sum = w.sum;
endcomp;
compute pct_x;
  pct_x = x.sum / x_sum;
endcomp;
compute pct_w;
  pct_w = w.sum / w_sum;
endcomp;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;z1	z2	x	pct_x	w	pct_w
A	1	10	14.29%	20	20.00%
 	2	20	28.57%	30	30.00%
 	3	40	57.14%	50	50.00%
B	1	15	18.75%	30	27.27%
 	2	25	31.25%	30	27.27%
 	3	40	50.00%	50	45.45%&lt;/PRE&gt;</description>
    <pubDate>Sun, 09 Feb 2025 08:54:55 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2025-02-09T08:54:55Z</dc:date>
    <item>
      <title>PROC REPORT calculate percent</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-REPORT-calculate-percent/m-p/958772#M374175</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;What is the way to calculate percentage of X and of W for each group (group is defined by Z1).&lt;/P&gt;
&lt;P&gt;I want to calculate it via proc report and display the report via proc report&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;PRE&gt;&lt;FONT face="Consolas, Monaco, Andale Mono, Ubuntu Mono, monospace" color="#000000"&gt; &lt;BR /&gt;Data have;&lt;BR /&gt;input z1 $ Z2 x w;&lt;BR /&gt;cards; &lt;BR /&gt;A 1 10 20&lt;BR /&gt;A 2 20 30&lt;BR /&gt;A 3 40 50&lt;BR /&gt;B 1 15 30&lt;BR /&gt;B 2 25 30&lt;BR /&gt;B 3 40 50&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table t1 as&lt;BR /&gt;select sum(X) as TOTAL_X,&lt;BR /&gt;sum(w) as TOTAL_w&lt;BR /&gt;from have&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;BR /&gt;data t2;&lt;BR /&gt;set have ;&lt;BR /&gt;if _n_=1 then set t1;&lt;BR /&gt;PCT_X=X/TOTAL_X;&lt;BR /&gt;PCT_W=W/TOTAL_w;&lt;BR /&gt;format PCT_X PCT_W percent8.1;&lt;BR /&gt;Run;&lt;BR /&gt;proc report data=t2;&lt;BR /&gt;run;&lt;BR /&gt;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 09 Feb 2025 06:56:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-REPORT-calculate-percent/m-p/958772#M374175</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2025-02-09T06:56:08Z</dc:date>
    </item>
    <item>
      <title>Re: PROC REPORT calculate percent</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-REPORT-calculate-percent/m-p/958773#M374176</link>
      <description>&lt;P&gt;Define both z1 and z2 as group, calculate sums for groups defined by z1, and the compute the percentages:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input z1 $ z2 x w;
cards; 
A 1 10 20
A 2 20 30
A 3 40 50
B 1 15 30
B 2 25 30
B 3 40 50
;

proc report data=have;
column z1 z2 x pct_x w pct_w;
define z1 / group;
define z2 / group;
define x / analysis;
define pct_x / computed format=percent8.2;
define w / analysis;
define pct_w / computed format=percent8.2;
compute before z1;
  x_sum = x.sum;
  w_sum = w.sum;
endcomp;
compute pct_x;
  pct_x = x.sum / x_sum;
endcomp;
compute pct_w;
  pct_w = w.sum / w_sum;
endcomp;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;z1	z2	x	pct_x	w	pct_w
A	1	10	14.29%	20	20.00%
 	2	20	28.57%	30	30.00%
 	3	40	57.14%	50	50.00%
B	1	15	18.75%	30	27.27%
 	2	25	31.25%	30	27.27%
 	3	40	50.00%	50	45.45%&lt;/PRE&gt;</description>
      <pubDate>Sun, 09 Feb 2025 08:54:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-REPORT-calculate-percent/m-p/958773#M374176</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-02-09T08:54:55Z</dc:date>
    </item>
    <item>
      <title>Re: PROC REPORT calculate percent</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-REPORT-calculate-percent/m-p/958784#M374182</link>
      <description>&lt;P&gt;I would prefer to use PROC SQL rather than PROC REPORT to get it .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; 
Data have;
input z1 $ Z2 x w;
cards; 
A 1 10 20
A 2 20 30
A 3 40 50
B 1 15 30
B 2 25 30
B 3 40 50
;
run;

proc report data=have nowd;
columns z1 z2 x w total_x total_w pct_x pct_w;
define z1/display;
define z2/display;
define x/analysis sum;
define w/analysis sum;
define total_x/computed;
define total_w/computed;
define pct_x/computed format=percent7.1;
define pct_w/computed format=percent7.1;

compute before ;
x_sum=x.sum;
w_sum=w.sum;
endcomp;
compute total_x;
total_x=x_sum;
endcomp;
compute total_w;
total_w=w_sum;
endcomp;
compute pct_x;
pct_x=x.sum/x_sum;
endcomp;
compute pct_w;
pct_w=w.sum/w_sum;
endcomp;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1739150677444.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/104505i218809EAC6E73A1C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1739150677444.png" alt="Ksharp_0-1739150677444.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Feb 2025 01:24:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-REPORT-calculate-percent/m-p/958784#M374182</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-02-10T01:24:47Z</dc:date>
    </item>
  </channel>
</rss>

