<?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: Obtain the percent sum by multiple groups in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Obtain-the-percent-sum-by-multiple-groups/m-p/858120#M339039</link>
    <description>&lt;P&gt;Ah, ok. Thanks again!&lt;/P&gt;</description>
    <pubDate>Thu, 09 Feb 2023 18:55:31 GMT</pubDate>
    <dc:creator>acrosb</dc:creator>
    <dc:date>2023-02-09T18:55:31Z</dc:date>
    <item>
      <title>Obtain the percent sum by multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtain-the-percent-sum-by-multiple-groups/m-p/858083#M339027</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have data that looks like this:&lt;/P&gt;&lt;P&gt;yyyymm&amp;nbsp; &amp;nbsp; channel&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;revenue&lt;/P&gt;&lt;P&gt;202001&amp;nbsp; &amp;nbsp; &amp;nbsp;standard&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $150&lt;/P&gt;&lt;P&gt;202001&amp;nbsp; &amp;nbsp; &amp;nbsp;non-standard&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;$200&lt;/P&gt;&lt;P&gt;202001&amp;nbsp; &amp;nbsp; &amp;nbsp;hybrid&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;$50&lt;/P&gt;&lt;P&gt;202002&amp;nbsp; &amp;nbsp; &amp;nbsp;standard&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;$100&lt;/P&gt;&lt;P&gt;202002&amp;nbsp; &amp;nbsp; &amp;nbsp;non-standard&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;$100&lt;/P&gt;&lt;P&gt;202002&amp;nbsp; &amp;nbsp; &amp;nbsp;hybrid&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;$100&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to report the percent of revenue coming from each channel in each month. Here is the output I'm looking for:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 202001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 202002&lt;/P&gt;&lt;P&gt;standard&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 37.5%&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;33.3%&lt;/P&gt;&lt;P&gt;non-standard&amp;nbsp; &amp;nbsp; &amp;nbsp;50%&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;33.3%&lt;/P&gt;&lt;P&gt;hybrid&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12.5%&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;33.3%&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The below sql code give me the correct numbers (the percent), but the format of the table/output is not want I want. I attempted to do the procedure in proc freq and proc tabulate, but I can't seem to get those to work. The freq code below takes a really long time to run, so I actually don't know if it does give the correct results. Can anyone help with this?&lt;/P&gt;&lt;PRE&gt;proc sql;
create table temp2 as
select yyyymm, channel, revenue, revenue/sum(revenue) as pctPop format=percent8.1
from (select yyyymm, channel, sum(revenue) as revenue from temp1 group by yyyymm, channel)
group by yyyymm;
select * from temp2;
quit;

proc freq data=temp1;
  tables revenue*(yyyymm channel);
run;

proc tabulate data=temp1;
class channel yyyymm;
var revenue;
table channel, pctsum*niw*yyyymm;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Feb 2023 16:38:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtain-the-percent-sum-by-multiple-groups/m-p/858083#M339027</guid>
      <dc:creator>acrosb</dc:creator>
      <dc:date>2023-02-09T16:38:39Z</dc:date>
    </item>
    <item>
      <title>Re: Obtain the percent sum by multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtain-the-percent-sum-by-multiple-groups/m-p/858087#M339028</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
informat yyyymm yymmn6. channel $15. revenue dollar.;
format yyyymm yymmn6. revenue dollar8.;
input yyyymm    channel           revenue ;
cards;
202001     standard              $150
202001     non-standard       $200
202001     hybrid                  $50
202002     standard              $100
202002     non-standard      $100
202002     hybrid                  $100
;;;;
run;

proc tabulate data=have;
class channel yyyymm;
table channel, yyyymm*(colpctn);
freq revenue;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This should get you closer using just PROC TABULATE if your dollars are all whole units. Not sure how it works if they're decimals.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2023 16:59:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtain-the-percent-sum-by-multiple-groups/m-p/858087#M339028</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-02-09T16:59:46Z</dc:date>
    </item>
    <item>
      <title>Re: Obtain the percent sum by multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtain-the-percent-sum-by-multiple-groups/m-p/858089#M339030</link>
      <description>&lt;P&gt;For percents, you can use PROC FREQ&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have;
    by yyyymm;
    table channel;
    weight revenue;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have;
    table channel*yyyymm/norow nopercent;
    weight revenue;
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;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/104334"&gt;@acrosb&lt;/a&gt;&amp;nbsp;Please notice how&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;has modified your data to be SAS data step code. That is how you should present data from now on.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2023 17:14:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtain-the-percent-sum-by-multiple-groups/m-p/858089#M339030</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-02-09T17:14:04Z</dc:date>
    </item>
    <item>
      <title>Re: Obtain the percent sum by multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtain-the-percent-sum-by-multiple-groups/m-p/858095#M339031</link>
      <description>&lt;P&gt;Thank you for your help! This is perfect.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2023 17:29:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtain-the-percent-sum-by-multiple-groups/m-p/858095#M339031</guid>
      <dc:creator>acrosb</dc:creator>
      <dc:date>2023-02-09T17:29:15Z</dc:date>
    </item>
    <item>
      <title>Re: Obtain the percent sum by multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtain-the-percent-sum-by-multiple-groups/m-p/858096#M339032</link>
      <description>&lt;P&gt;Thank you! Yes, I will present my data in a data step from now on.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2023 17:29:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtain-the-percent-sum-by-multiple-groups/m-p/858096#M339032</guid>
      <dc:creator>acrosb</dc:creator>
      <dc:date>2023-02-09T17:29:46Z</dc:date>
    </item>
    <item>
      <title>Re: Obtain the percent sum by multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtain-the-percent-sum-by-multiple-groups/m-p/858101#M339033</link>
      <description>&lt;P&gt;When I output the Tabulate results (using "out=datasetname" in the proc tabulate statement), the columns/rows flip. Is there any (simple) way to keep the format of the table when putting it into a dataset? I was the years/months to be columns in my outputted dataset.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2023 17:59:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtain-the-percent-sum-by-multiple-groups/m-p/858101#M339033</guid>
      <dc:creator>acrosb</dc:creator>
      <dc:date>2023-02-09T17:59:25Z</dc:date>
    </item>
    <item>
      <title>Re: Obtain the percent sum by multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtain-the-percent-sum-by-multiple-groups/m-p/858109#M339037</link>
      <description>&lt;P&gt;Unfortunately not, but you can use PROC TRANSPOSE to flip it back.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=long out=want;
by channel;
id yyyymm;
var pctn_01;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Feb 2023 18:27:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtain-the-percent-sum-by-multiple-groups/m-p/858109#M339037</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-02-09T18:27:49Z</dc:date>
    </item>
    <item>
      <title>Re: Obtain the percent sum by multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtain-the-percent-sum-by-multiple-groups/m-p/858120#M339039</link>
      <description>&lt;P&gt;Ah, ok. Thanks again!&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2023 18:55:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtain-the-percent-sum-by-multiple-groups/m-p/858120#M339039</guid>
      <dc:creator>acrosb</dc:creator>
      <dc:date>2023-02-09T18:55:31Z</dc:date>
    </item>
  </channel>
</rss>

