<?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 SQL: Union all expands the result with every repetition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SQL-Union-all-expands-the-result-with-every-repetition/m-p/835527#M330320</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;with sql I want to create a new dataset that creates also a summarized row. The following code shows what I mean and where my problem is: When I execute this code once, it works. But if I execute it twice or more, the summarized row expands with every repetition. Do you have a clue why this is happen and which way could be the better one?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table Kategorietest as select
 	sex, 
  	sum(case when age&amp;gt;=13 then weight end) as Teen,
   	sum(case when age&amp;lt;13 then weight end) as Kid,
	count(case when age &amp;lt;13 then age end) as Anzahl
from sashelp.class
group by sex
union all
select "Total",sum(Teen),sum(kid),Sum(anzahl) from Kategorietest;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 28 Sep 2022 05:53:45 GMT</pubDate>
    <dc:creator>Konkordanz</dc:creator>
    <dc:date>2022-09-28T05:53:45Z</dc:date>
    <item>
      <title>SQL: Union all expands the result with every repetition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-Union-all-expands-the-result-with-every-repetition/m-p/835527#M330320</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;with sql I want to create a new dataset that creates also a summarized row. The following code shows what I mean and where my problem is: When I execute this code once, it works. But if I execute it twice or more, the summarized row expands with every repetition. Do you have a clue why this is happen and which way could be the better one?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table Kategorietest as select
 	sex, 
  	sum(case when age&amp;gt;=13 then weight end) as Teen,
   	sum(case when age&amp;lt;13 then weight end) as Kid,
	count(case when age &amp;lt;13 then age end) as Anzahl
from sashelp.class
group by sex
union all
select "Total",sum(Teen),sum(kid),Sum(anzahl) from Kategorietest;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Sep 2022 05:53:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-Union-all-expands-the-result-with-every-repetition/m-p/835527#M330320</guid>
      <dc:creator>Konkordanz</dc:creator>
      <dc:date>2022-09-28T05:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: SQL: Union all expands the result with every repetition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-Union-all-expands-the-result-with-every-repetition/m-p/835529#M330322</link>
      <description>&lt;P&gt;It is always a bad idea to use the same dataset in CREATE TABLE and FROM, PROC SQL should write a message to the log.&lt;/P&gt;
&lt;P&gt;Create both parts from the source dataset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table Kategorietest as select
  sex, 
  sum(case when age&amp;gt;=13 then weight end) as Teen,
  sum(case when age&amp;lt;13 then weight end) as Kid,
  count(case when age &amp;lt;13 then age end) as Anzahl
from sashelp.class
group by sex
union all
select
  "Total",
  sum(case when age&amp;gt;=13 then weight end) as Teen,
  sum(case when age&amp;lt;13 then weight end) as Kid,
  count(case when age &amp;lt;13 then age end) as Anzahl
from sashelp.class;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Sep 2022 06:59:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-Union-all-expands-the-result-with-every-repetition/m-p/835529#M330322</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-09-28T06:59:09Z</dc:date>
    </item>
    <item>
      <title>Re: SQL: Union all expands the result with every repetition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-Union-all-expands-the-result-with-every-repetition/m-p/835531#M330323</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 28 Sep 2022 07:25:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-Union-all-expands-the-result-with-every-repetition/m-p/835531#M330323</guid>
      <dc:creator>Konkordanz</dc:creator>
      <dc:date>2022-09-28T07:25:39Z</dc:date>
    </item>
  </channel>
</rss>

