<?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: N, PCT,SUM, PCT SUM in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/N-PCT-SUM-PCT-SUM/m-p/862332#M340616</link>
    <description>&lt;P&gt;If your "what is the way" is expecting 4 solutions, why? Pick one and know why, or show what you have at least attempted for each.&lt;/P&gt;
&lt;P&gt;Personally I wouldn't even consider SQL for this because you have to merge multiple elements after figuring out how to do the basic calculations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Formats. You have three pieces that require custom formats, depending on approach.&lt;/P&gt;
&lt;P&gt;The reason I say three is because in the two most likely solutions I would do, Proc Tabulate and Report the Pct is not an actual decimal value. So you have to fudge to get a percent sign. You also don't say anything about how many decimals you want in your "millions" result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My take:&lt;/P&gt;
&lt;PRE&gt;proc format;
value $myorigin
'Asia' = 'Asia'
'USA','Europe' = 'Europe, USA'
; 
picture fakepct
low-high = '009.9%' ;
picture millions (fuzz=0)
   low-high='0000 M' ( mult=.000001)
;
run;

proc tabulate data=sashelp.cars;
   class origin/order=freq;
   format origin $myorigin.;
   var msrp   ;              ;
   table origin=' ' All='Total',
         n='Nr' pctn='PCT'*f=fakepct. 
         msrp=' '*(sum='Sum_MSRP'*f=millions. pctsum='PCT_MSRP'*f=fakepct.)
         /box='Origin'
   ;
run;
          &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 07 Mar 2023 18:33:26 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-03-07T18:33:26Z</dc:date>
    <item>
      <title>N, PCT,SUM, PCT SUM</title>
      <link>https://communities.sas.com/t5/SAS-Programming/N-PCT-SUM-PCT-SUM/m-p/862307#M340603</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to use sashelp.cars&amp;nbsp; data set to create the following report.&lt;/P&gt;
&lt;P&gt;For each Origin category to calculate:&lt;/P&gt;
&lt;P&gt;Number of observations (Nr)&lt;/P&gt;
&lt;P&gt;Percent of observations from total observations (PCT)&lt;/P&gt;
&lt;P&gt;Sum of MSRP (Sum_MSRP)&lt;/P&gt;
&lt;P&gt;Percentage of sum MSRP&amp;nbsp; from total (PCT_MSRP)&lt;/P&gt;
&lt;P&gt;I want to dissplay percentage in %&amp;nbsp; with format percent8.1&lt;/P&gt;
&lt;P&gt;I want to define Europe+USA&amp;nbsp; as one category together&lt;/P&gt;
&lt;P&gt;I want that order of rows will be from highest freq (desending)&lt;/P&gt;
&lt;P&gt;I want to diaplay sum_MSRO&amp;nbsp; in millions&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ronein_0-1677950416467.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/81066iC91584EF4AD67D36/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ronein_0-1677950416467.png" alt="Ronein_0-1677950416467.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;What is the way to do it via-&lt;/P&gt;
&lt;P&gt;proc means&lt;/P&gt;
&lt;P&gt;proc tabulate&lt;/P&gt;
&lt;P&gt;proc Report&lt;/P&gt;
&lt;P&gt;proc sql&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Mar 2023 17:26:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/N-PCT-SUM-PCT-SUM/m-p/862307#M340603</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-03-04T17:26:27Z</dc:date>
    </item>
    <item>
      <title>Re: N, PCT,SUM, PCT SUM</title>
      <link>https://communities.sas.com/t5/SAS-Programming/N-PCT-SUM-PCT-SUM/m-p/862330#M340615</link>
      <description>Hi:&lt;BR /&gt;  What code have you tried? My tendency would be to use either PROC REPORT or PROC TABULATE. I expect that you'll need a user-defined format to have Europe and USA treated as one category. Otherwise, the statistics are fairly straightforward with both PROC TABULATE and PROC REPORT. I'm probably learning more toward TABULATE at this point.&lt;BR /&gt;Cynthia</description>
      <pubDate>Sun, 05 Mar 2023 01:57:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/N-PCT-SUM-PCT-SUM/m-p/862330#M340615</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2023-03-05T01:57:18Z</dc:date>
    </item>
    <item>
      <title>Re: N, PCT,SUM, PCT SUM</title>
      <link>https://communities.sas.com/t5/SAS-Programming/N-PCT-SUM-PCT-SUM/m-p/862332#M340616</link>
      <description>&lt;P&gt;If your "what is the way" is expecting 4 solutions, why? Pick one and know why, or show what you have at least attempted for each.&lt;/P&gt;
&lt;P&gt;Personally I wouldn't even consider SQL for this because you have to merge multiple elements after figuring out how to do the basic calculations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Formats. You have three pieces that require custom formats, depending on approach.&lt;/P&gt;
&lt;P&gt;The reason I say three is because in the two most likely solutions I would do, Proc Tabulate and Report the Pct is not an actual decimal value. So you have to fudge to get a percent sign. You also don't say anything about how many decimals you want in your "millions" result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My take:&lt;/P&gt;
&lt;PRE&gt;proc format;
value $myorigin
'Asia' = 'Asia'
'USA','Europe' = 'Europe, USA'
; 
picture fakepct
low-high = '009.9%' ;
picture millions (fuzz=0)
   low-high='0000 M' ( mult=.000001)
;
run;

proc tabulate data=sashelp.cars;
   class origin/order=freq;
   format origin $myorigin.;
   var msrp   ;              ;
   table origin=' ' All='Total',
         n='Nr' pctn='PCT'*f=fakepct. 
         msrp=' '*(sum='Sum_MSRP'*f=millions. pctsum='PCT_MSRP'*f=fakepct.)
         /box='Origin'
   ;
run;
          &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2023 18:33:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/N-PCT-SUM-PCT-SUM/m-p/862332#M340616</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-03-07T18:33:26Z</dc:date>
    </item>
    <item>
      <title>Re: N, PCT,SUM, PCT SUM</title>
      <link>https://communities.sas.com/t5/SAS-Programming/N-PCT-SUM-PCT-SUM/m-p/862624#M340744</link>
      <description>Can you show your proc report code for this task?</description>
      <pubDate>Tue, 07 Mar 2023 07:56:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/N-PCT-SUM-PCT-SUM/m-p/862624#M340744</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-03-07T07:56:53Z</dc:date>
    </item>
    <item>
      <title>Re: N, PCT,SUM, PCT SUM</title>
      <link>https://communities.sas.com/t5/SAS-Programming/N-PCT-SUM-PCT-SUM/m-p/862754#M340788</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Sure, here's the PROC REPORT code. I used 2 of your formats, but did not use the fakepct format -- that's was only needed for TABULATE. REPORT can use the regular SAS PERCENT format. I used 2 decimal places to show how the percents do add up to 100.00%&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_0-1678213844800.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/81169i52DFC04A350208DA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_0-1678213844800.png" alt="Cynthia_sas_0-1678213844800.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2023 18:31:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/N-PCT-SUM-PCT-SUM/m-p/862754#M340788</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2023-03-07T18:31:06Z</dc:date>
    </item>
  </channel>
</rss>

