<?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 PROC SQL to take summary info from a disaggregated-set in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-to-take-summary-info-from-a-disaggregated-set/m-p/669994#M201073</link>
    <description>&lt;P&gt;Dear All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have two sets, one is at an aggregated-level while the other is at a disaggregated-level. I would like to merge summary stat (e.g., mean, sum) from the second set with the first set by using proc SQL.&amp;nbsp;&lt;SPAN style="font-family: inherit;"&gt;I did this as shown below. I think it could be shorter, but I don't know how to do so. Please keep in mind that the aggregated-level has another variable that is not included in the the other data set. So I would like to use proc SQL to get summary information from the disaggregated set.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To illustrate, I generated the two datasets.&lt;/P&gt;
&lt;P&gt;- ID_set: Set at an aggregated-level.&lt;/P&gt;
&lt;P&gt;- Data_set: Set at a disaggregated-level.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Generating ID_Set;
data ID_set;
	set sashelp.cars;
	keep Make Type; 
	run;

proc sort data= ID_set 
	nodupkey; 
	by Make;
	run;
	*N= 38;

*Generating Data_Set;
data Data_set;
	set sashelp.cars;
	keep Make EngineSize;
	run;
	*N= 428;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using the two datasets,&amp;nbsp;I would like to calculate sum and average of EngineSize and attach them to the first data set. I did PROC SQL and PROC SORT to keep the unique observations at an aggregated-level. I feel like they can be done at once in PROC SQL (without PROC SORT), but I don't know how to do so. Any help would be appreciated!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table Merged
	as select a.*, 
		sum(b.EngineSize) as Sum_Engine,
		Mean(b.EngineSize) as Mean_Engine
	from ID_set a left join Data_set b
	on a.Make= b.Make
	group by a.Make;
	quit;

proc sort data= Merged nodupkey;
	by Make;
	run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 16 Jul 2020 21:29:46 GMT</pubDate>
    <dc:creator>braam</dc:creator>
    <dc:date>2020-07-16T21:29:46Z</dc:date>
    <item>
      <title>PROC SQL to take summary info from a disaggregated-set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-to-take-summary-info-from-a-disaggregated-set/m-p/669994#M201073</link>
      <description>&lt;P&gt;Dear All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have two sets, one is at an aggregated-level while the other is at a disaggregated-level. I would like to merge summary stat (e.g., mean, sum) from the second set with the first set by using proc SQL.&amp;nbsp;&lt;SPAN style="font-family: inherit;"&gt;I did this as shown below. I think it could be shorter, but I don't know how to do so. Please keep in mind that the aggregated-level has another variable that is not included in the the other data set. So I would like to use proc SQL to get summary information from the disaggregated set.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To illustrate, I generated the two datasets.&lt;/P&gt;
&lt;P&gt;- ID_set: Set at an aggregated-level.&lt;/P&gt;
&lt;P&gt;- Data_set: Set at a disaggregated-level.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Generating ID_Set;
data ID_set;
	set sashelp.cars;
	keep Make Type; 
	run;

proc sort data= ID_set 
	nodupkey; 
	by Make;
	run;
	*N= 38;

*Generating Data_Set;
data Data_set;
	set sashelp.cars;
	keep Make EngineSize;
	run;
	*N= 428;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using the two datasets,&amp;nbsp;I would like to calculate sum and average of EngineSize and attach them to the first data set. I did PROC SQL and PROC SORT to keep the unique observations at an aggregated-level. I feel like they can be done at once in PROC SQL (without PROC SORT), but I don't know how to do so. Any help would be appreciated!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table Merged
	as select a.*, 
		sum(b.EngineSize) as Sum_Engine,
		Mean(b.EngineSize) as Mean_Engine
	from ID_set a left join Data_set b
	on a.Make= b.Make
	group by a.Make;
	quit;

proc sort data= Merged nodupkey;
	by Make;
	run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jul 2020 21:29:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-to-take-summary-info-from-a-disaggregated-set/m-p/669994#M201073</guid>
      <dc:creator>braam</dc:creator>
      <dc:date>2020-07-16T21:29:46Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL to take summary info from a disaggregated-set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-to-take-summary-info-from-a-disaggregated-set/m-p/670003#M201076</link>
      <description>&lt;P&gt;So you want summaries in your data at the make level but the data table at a make/engine size categories?&lt;/P&gt;
&lt;P&gt;TYPE is just the first record? It doesn't matter which one you take? Do you need it the logic for what's first to be consistent at least? Your current code doesn't guarantee that.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jul 2020 21:50:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-to-take-summary-info-from-a-disaggregated-set/m-p/670003#M201076</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-07-16T21:50:28Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL to take summary info from a disaggregated-set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-to-take-summary-info-from-a-disaggregated-set/m-p/670011#M201078</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table Merged as 
       select a.*,
                 b. Sum_Engine,
                 b.Mean_Engine
       from       ID_set a 
       left join  (
                      select Make,
                                 sum(EngineSize) as Sum_Engine,
		                 Mean(EngineSize) as Mean_Engine
                      from Data_set
                      group by a.Make
                    ) b on a.Make= b.Make
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Jul 2020 22:20:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-to-take-summary-info-from-a-disaggregated-set/m-p/670011#M201078</guid>
      <dc:creator>sotojcr</dc:creator>
      <dc:date>2020-07-16T22:20:37Z</dc:date>
    </item>
  </channel>
</rss>

