<?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: summary data set by groups SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/summary-data-set-by-groups-SQL/m-p/548433#M152081</link>
    <description>&lt;P&gt;could you please show what exactly you have in your hand and what you want as an output dataset.&lt;/P&gt;</description>
    <pubDate>Thu, 04 Apr 2019 08:38:57 GMT</pubDate>
    <dc:creator>Shivam</dc:creator>
    <dc:date>2019-04-04T08:38:57Z</dc:date>
    <item>
      <title>summary data set by groups SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/summary-data-set-by-groups-SQL/m-p/548291#M152025</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Good afternoon,&lt;/P&gt;&lt;P&gt;This is probably a very simple question but I cannot find how to get the final table that I need.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc SQL;
Create table work.sales_sales1 AS 
SELECT report_month, Sales_Channel,
Count(distinct CustomerID) AS CountCustomers, 
Count(distinct SalesRepID) AS CountSalesRep,
Sum(Cost) AS TotalCost,
from work.sales_details
group by sales_channel, report_month;
quit;

proc print data=sales_sales1; run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The final output gives me a display of all the different observations listed in order of sales_channel and report_month, but what I really need is a data set that summarizes these new variables by each category of the variables:&amp;nbsp; sales_channel and Report_month.&lt;/P&gt;&lt;P&gt;thank you in advance for your help&lt;/P&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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2019 18:06:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/summary-data-set-by-groups-SQL/m-p/548291#M152025</guid>
      <dc:creator>Dublin187</dc:creator>
      <dc:date>2019-04-03T18:06:23Z</dc:date>
    </item>
    <item>
      <title>Re: summary data set by groups SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/summary-data-set-by-groups-SQL/m-p/548294#M152028</link>
      <description>&lt;P&gt;Can you post a sample of what you HAVE and what you WANT as output plz?&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2019 18:11:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/summary-data-set-by-groups-SQL/m-p/548294#M152028</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-03T18:11:02Z</dc:date>
    </item>
    <item>
      <title>Re: summary data set by groups SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/summary-data-set-by-groups-SQL/m-p/548305#M152032</link>
      <description>&lt;P&gt;here is something that might work.&amp;nbsp; good luck&lt;/P&gt;&lt;PRE&gt;Proc SQL;
Create table work.sales_sales1 AS 
SELECT 
	a.report_month
	, a.Sales_Channel
	, Count(b.CustomerID) AS CountCustomers
	, Count(c.SalesRepID) AS CountSalesRep
	, Sum(Cost) AS TotalCost
from 
	work.sales_details a
	LEFT JOIN /*Derived table below to get distinct CustomerID's for each SalesChannel/ReportMonth*/
		(SELECT DISTINCT CustomerID, sales_channel, report_month FROM work.sales_details) b ON a.sales_channel = b.sales_channel and a.report_month = b.report_month 
	LEFT JOIN /*Derived table below to get distinct SalesRepID's for each SalesChannel/ReportMonth*/	
		(SELECT DISTINCT SalesRepID, sales_channel, report_month FROM work.sales_details) c ON a.sales_channel = c.sales_channel and a.report_month = c.report_month 
group by sales_channel, report_month

;
quit;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Apr 2019 19:02:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/summary-data-set-by-groups-SQL/m-p/548305#M152032</guid>
      <dc:creator>utrocketeng</dc:creator>
      <dc:date>2019-04-03T19:02:37Z</dc:date>
    </item>
    <item>
      <title>Re: summary data set by groups SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/summary-data-set-by-groups-SQL/m-p/548433#M152081</link>
      <description>&lt;P&gt;could you please show what exactly you have in your hand and what you want as an output dataset.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2019 08:38:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/summary-data-set-by-groups-SQL/m-p/548433#M152081</guid>
      <dc:creator>Shivam</dc:creator>
      <dc:date>2019-04-04T08:38:57Z</dc:date>
    </item>
    <item>
      <title>Re: summary data set by groups SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/summary-data-set-by-groups-SQL/m-p/548474#M152093</link>
      <description>&lt;P&gt;i do not feel the previous solution i provided will work.&amp;nbsp; this might be a better approach.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Proc SQL;
Create view work.NCustomerID AS
SELECT COUNT(CustomerID) as NCustomerID, sales_channel, report_month
FROM
	(
	SELECT DISTINCT CustomerID, sales_channel, report_month FROM work.sales_details
	) a
group by sales_channel, report_month
;

Create view work.NSalesRepID AS
SELECT COUNT(SalesRepID) as NSalesRepID, sales_channel, report_month
FROM
	(
	SELECT DISTINCT SalesRepID, sales_channel, report_month FROM work.sales_details
	) a
group by sales_channel, report_month
;

Create view work.TotalCost AS 
SELECT 
	a.report_month
	, a.Sales_Channel
	, Sum(Cost) AS TotalCost
from 
	work.sales_details a
group by sales_channel, report_month

;
Create table work.sales_sales1 AS 
SELECT 
	a.report_month
	, a.Sales_Channel
	, TotalCost
	, NCustomerID
	, NSalesRepID
from 
	work.TotalCost a
	LEFT JOIN work.NCustomerID b ON a.sales_channel = b.sales_channel and a.report_month = b.report_month 
	LEFT JOIN work.NSalesRepID c ON a.sales_channel = c.sales_channel and a.report_month = c.report_month 
;
quit;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Apr 2019 12:35:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/summary-data-set-by-groups-SQL/m-p/548474#M152093</guid>
      <dc:creator>utrocketeng</dc:creator>
      <dc:date>2019-04-04T12:35:09Z</dc:date>
    </item>
    <item>
      <title>Re: summary data set by groups SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/summary-data-set-by-groups-SQL/m-p/548480#M152095</link>
      <description>&lt;P&gt;It sounds like you are asking for exactly what that code is giving you.&lt;/P&gt;
&lt;P&gt;Perhaps you meant that you want separate reports summarized by the two variables independently?&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2019 12:59:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/summary-data-set-by-groups-SQL/m-p/548480#M152095</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-04-04T12:59:07Z</dc:date>
    </item>
  </channel>
</rss>

