<?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: aggregation simple statistics to different groups in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/aggregation-simple-statistics-to-different-groups/m-p/920137#M362402</link>
    <description>&lt;P&gt;PROC SUMMARY/PROC MEANS with multi-label formats.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/proc/n13dhme6o4ut3en1u8e58r16b3zf.htm#n13dhme6o4ut3en1u8e58r16b3zf" target="_blank" rel="noopener"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/proc/n13dhme6o4ut3en1u8e58r16b3zf.htm#n13dhme6o4ut3en1u8e58r16b3zf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IMHO, PROC SUMMARY/PROC MEANS should always be the choice for computing a lot of statistics. IMHO, SQL should be the last choice for computing a lot of statistics.&lt;/P&gt;</description>
    <pubDate>Wed, 13 Mar 2024 14:40:33 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2024-03-13T14:40:33Z</dc:date>
    <item>
      <title>aggregation simple statistics to different groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/aggregation-simple-statistics-to-different-groups/m-p/920112#M362397</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to calculate aggregation simple statistics to different groups.&lt;/P&gt;
&lt;P&gt;Is there a shorter code that&amp;nbsp; can produce same results?&lt;/P&gt;
&lt;P&gt;Maybe via proc format?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table Want as 
select Type,
       count(*) as nr_rows  format=comma28.,
	   sum(MSRP) as SUM_MSRP  format=comma28.,
	   sum(Invoice) as SUM_Invoice format=comma28.
from  sashelp.cars
group by Type
union all
select 'SUV+Sports' as Type,
       count(*) as nr_rows  format=comma28.,
	   sum(MSRP) as SUM_MSRP  format=comma28.,
	   sum(Invoice) as SUM_Invoice format=comma28.
from  sashelp.cars
where Type  in ('SUV','Sports')
union all
select 'SUV+Hybrid' as Type,
       count(*) as nr_rows  format=comma28.,
	   sum(MSRP) as SUM_MSRP  format=comma28.,
	   sum(Invoice) as SUM_Invoice format=comma28.
from  sashelp.cars
where Type  in ('SUV','Hybrid')
union all
select 'Hybrid+SUV+Sedan+Sports' as Type,
       count(*) as nr_rows  format=comma28.,
	   sum(MSRP) as SUM_MSRP  format=comma28.,
	   sum(Invoice) as SUM_Invoice format=comma28.
from  sashelp.cars
where Type  in ('Hybrid','SUV','Sedan','Sports')
union all
select ' Truck+Wagon' as Type,
       count(*) as nr_rows  format=comma28.,
	   sum(MSRP) as SUM_MSRP  format=comma28.,
	   sum(Invoice) as SUM_Invoice format=comma28.
from  sashelp.cars
where Type  in ('Truck','Wagon')
union all
select 'ALL' as Type,
       count(*) as nr_rows  format=comma28.,
	   sum(MSRP) as SUM_MSRP  format=comma28.,
	   sum(Invoice) as SUM_Invoice format=comma28.
from  sashelp.cars
;
quit;


 
 &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Mar 2024 12:55:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/aggregation-simple-statistics-to-different-groups/m-p/920112#M362397</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-03-13T12:55:42Z</dc:date>
    </item>
    <item>
      <title>Re: aggregation simple statistics to different groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/aggregation-simple-statistics-to-different-groups/m-p/920137#M362402</link>
      <description>&lt;P&gt;PROC SUMMARY/PROC MEANS with multi-label formats.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/proc/n13dhme6o4ut3en1u8e58r16b3zf.htm#n13dhme6o4ut3en1u8e58r16b3zf" target="_blank" rel="noopener"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/proc/n13dhme6o4ut3en1u8e58r16b3zf.htm#n13dhme6o4ut3en1u8e58r16b3zf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IMHO, PROC SUMMARY/PROC MEANS should always be the choice for computing a lot of statistics. IMHO, SQL should be the last choice for computing a lot of statistics.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2024 14:40:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/aggregation-simple-statistics-to-different-groups/m-p/920137#M362402</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-03-13T14:40:33Z</dc:date>
    </item>
    <item>
      <title>Re: aggregation simple statistics to different groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/aggregation-simple-statistics-to-different-groups/m-p/920139#M362403</link>
      <description>&lt;PRE&gt;proc format;
	value $type (multilabel notsorted)
		"SUV"    = "SUV"
		"Wagon"  = "Wagon"
		"Sports" = "Sports"
		"Sedan"  = "Sedan"
		"Truck"  = "Truck"
		"Hybrid" = "Hybrid"
		"SUV", "Truck", "Hybrid", "Wagon", "Sedan", "Sports" = "All"
		"SUV", "Sports" = "SUV+Sports"
		"SUV", "Hybrid" = "SUV+Hybrid"
		"Hybrid", "SUV", "Sedan", "Sports" = "Hybrid+SUV+Sedan+Sports"
		"Truck", "Wagon" = "Truck+Wagon";
run;


proc means data=sashelp.cars completetypes nway;
	class type / mlf preloadfmt order=formatted exclusive;
	format type $type.;
	var msrp invoice;
	output out = want
	 sum(msrp invoice)=/autoname;
run;&lt;/PRE&gt;&lt;P&gt;can you try this ?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2024 15:11:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/aggregation-simple-statistics-to-different-groups/m-p/920139#M362403</guid>
      <dc:creator>Mazi</dc:creator>
      <dc:date>2024-03-13T15:11:14Z</dc:date>
    </item>
  </channel>
</rss>

