<?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 and group percents in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-report-and-group-percents/m-p/946298#M370608</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt; -- I agree with you. If someone is not comfortable with PROC REPORT and using helper variables and COMPUTE blocks, then pre-summarizing and computing the percents in a DATA step or switching to PROC TABULATE (which has custom denominators and also the ROWPCT/COLPCT statistics) is a preferred approach.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; For the sake of completeness, here's an example of how to do it within PROC REPORT using helper variables. I switched to using SASHELP.SHOES because the OP did not provide data. This report has a percent of region and then a fake percent where the denominator was set to a constant value of 3371.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_0-1728050946123.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/100929iD20C8DC67656E57A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_0-1728050946123.png" alt="Cynthia_sas_0-1728050946123.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Ths places where the 2 new percents are calculated are highlighted:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_1-1728051011199.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/100930i7D12C42BC2960CDE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_1-1728051011199.png" alt="Cynthia_sas_1-1728051011199.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Basically, if you want to calculate percent of region with PROC REPORT, you have to "grab" and hold the count for that region into a helper variable called RCNT, which is automatically retained and then use rcnt in the divide for REGPCT. The calculation for FAKEPCT just uses a numeric constant as the denominator.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;</description>
    <pubDate>Fri, 04 Oct 2024 14:11:55 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2024-10-04T14:11:55Z</dc:date>
    <item>
      <title>proc report and group percents</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-report-and-group-percents/m-p/946260#M370596</link>
      <description>&lt;P&gt;Hello, I need some help with reporting percentages. I have a data set with list of cities and countries and am counting how often a city appears (for example Melbourne, Australia is in 18 rows, per proc report count n).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;pctn is calculating percent out of all countries? I think.&lt;/P&gt;&lt;P&gt;1. How would I calculate so each country is 100% and the city count percentages will add to 100% per country.&amp;nbsp; in the snippet below, Austria summary 100%, salzburg 66%/vienna 33%.&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. What if I wanted to calculate percent out of a completely different number? say "each city count"/1000. Can I define my own denominator in a calculate field?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc report data=city_data;&lt;/P&gt;&lt;P&gt;columns country city (n pctn);&lt;/P&gt;&lt;P&gt;define country /group;&lt;/P&gt;&lt;P&gt;define city /group;&lt;/P&gt;&lt;P&gt;define pctn /format =percent9.1 'Percent';&lt;/P&gt;&lt;P&gt;define n /'count';&lt;/P&gt;&lt;P&gt;rbreak before /summarize;&lt;/P&gt;&lt;P&gt;break before country/summarize style=header;&lt;/P&gt;&lt;P&gt;compute before;&lt;BR /&gt;country='All countries';&lt;BR /&gt;endcomp;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&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......&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2024 13:02:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-report-and-group-percents/m-p/946260#M370596</guid>
      <dc:creator>eawh100</dc:creator>
      <dc:date>2024-10-04T13:02:07Z</dc:date>
    </item>
    <item>
      <title>Re: proc report and group percents</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-report-and-group-percents/m-p/946274#M370598</link>
      <description>&lt;P&gt;My answer to both questions is to do the calculations and get them the way you want them to be before using PROC REPORT. For example, using PROC SUMMARY and/or PROC FREQ and/or DATA steps. If you do that, then PROC REPORT is simple to program. I say this because I feel much more comfortable using those tools to program with, rather than the internal tools in PROC REPORT.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2024 13:21:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-report-and-group-percents/m-p/946274#M370598</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-10-04T13:21:20Z</dc:date>
    </item>
    <item>
      <title>Re: proc report and group percents</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-report-and-group-percents/m-p/946280#M370600</link>
      <description>&lt;P&gt;ok, thanks. I'd just calculate whatever percents I want in a new column in say a data step and then use that new column within proc report?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2024 13:43:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-report-and-group-percents/m-p/946280#M370600</guid>
      <dc:creator>eawh100</dc:creator>
      <dc:date>2024-10-04T13:43:30Z</dc:date>
    </item>
    <item>
      <title>Re: proc report and group percents</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-report-and-group-percents/m-p/946291#M370606</link>
      <description>&lt;P&gt;Yes, all the info winds up in a data set, so you know you have done the calculations properly, and then that data set is used in PROC REPORT&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2024 14:03:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-report-and-group-percents/m-p/946291#M370606</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-10-04T14:03:43Z</dc:date>
    </item>
    <item>
      <title>Re: proc report and group percents</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-report-and-group-percents/m-p/946298#M370608</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt; -- I agree with you. If someone is not comfortable with PROC REPORT and using helper variables and COMPUTE blocks, then pre-summarizing and computing the percents in a DATA step or switching to PROC TABULATE (which has custom denominators and also the ROWPCT/COLPCT statistics) is a preferred approach.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; For the sake of completeness, here's an example of how to do it within PROC REPORT using helper variables. I switched to using SASHELP.SHOES because the OP did not provide data. This report has a percent of region and then a fake percent where the denominator was set to a constant value of 3371.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_0-1728050946123.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/100929iD20C8DC67656E57A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_0-1728050946123.png" alt="Cynthia_sas_0-1728050946123.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Ths places where the 2 new percents are calculated are highlighted:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_1-1728051011199.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/100930i7D12C42BC2960CDE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_1-1728051011199.png" alt="Cynthia_sas_1-1728051011199.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Basically, if you want to calculate percent of region with PROC REPORT, you have to "grab" and hold the count for that region into a helper variable called RCNT, which is automatically retained and then use rcnt in the divide for REGPCT. The calculation for FAKEPCT just uses a numeric constant as the denominator.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2024 14:11:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-report-and-group-percents/m-p/946298#M370608</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2024-10-04T14:11:55Z</dc:date>
    </item>
  </channel>
</rss>

