<?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: Create Grand Total Sum SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-Grand-Total-Sum-SQL/m-p/568851#M160220</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/267062"&gt;@OskarBlad&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;, but if you want to use SQL, you can make the table as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have (drop=i);
	do Groupingvariabel = 'Gruppe1', 'Gruppe2', 'Gruppe3', 'Gruppe4';
		do i = 1 to 10;
			t1 = int(ranuni(3)*100);
			t2 = int(ranuni(3)*100);
			t3 = int(ranuni(3)*100);
			t4 = int(ranuni(3)*100);
			output;
		end;
	end;
run;

proc sql;
	create table want (drop=type) as
		select 
			Groupingvariabel,
			sum(t1) as t1,
			sum(t2) as t2,
			sum(t3) as t3,
			sum(t4) as t4,
			1 as type
		from have
		group by Groupingvariabel
		union
		select
			'Total' as Groupingvariabel,
			sum(t1) as t1,
			sum(t2) as t2,
			sum(t3) as t3,
			sum(t4) as t4,
			2 as type
		from have
		order by 
			type,
			Groupingvariabel;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 25 Jun 2019 16:10:27 GMT</pubDate>
    <dc:creator>ErikLund_Jensen</dc:creator>
    <dc:date>2019-06-25T16:10:27Z</dc:date>
    <item>
      <title>Create Grand Total Sum SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Grand-Total-Sum-SQL/m-p/568840#M160213</link>
      <description>&lt;P&gt;I want to sum a columns value in the bottom of the table from a computed sum grouped by a column.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE Test AS&lt;BR /&gt;SELECT&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; t1.Groupingvariabel AS Group,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; SUM(t1.1) FORMAT NLNUM25. AS 1,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; SUM(t1.2) FORMAT NLNUM25. AS 2,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; SUM(t1.3) FORMAT NLNUM25. AS 3,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; SUM(t1.4) FORMAT NLNUM25. AS 4&lt;/P&gt;&lt;P&gt;FROM Dataset AS t1&lt;/P&gt;&lt;P&gt;GROUP BY t1.Groupingvariabel;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here I want to make an grand total for each of the variabel as a last row in the data set. I want to make it in one step, is it possible and then how? So I want a total row in the end of the dataset that sum each observation in each of the variabel 1, 2, 3 and 4 separately.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2019 15:44:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Grand-Total-Sum-SQL/m-p/568840#M160213</guid>
      <dc:creator>OskarBlad</dc:creator>
      <dc:date>2019-06-25T15:44:29Z</dc:date>
    </item>
    <item>
      <title>Re: Create Grand Total Sum SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Grand-Total-Sum-SQL/m-p/568845#M160216</link>
      <description>Is this for a data set or or a report. For reports it's very trivial, for data sets it's more of a pain. And are you set on using SQL? PROC MEANS is better as is PROC REPORT and TABULATE.</description>
      <pubDate>Tue, 25 Jun 2019 15:56:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Grand-Total-Sum-SQL/m-p/568845#M160216</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-06-25T15:56:32Z</dc:date>
    </item>
    <item>
      <title>Re: Create Grand Total Sum SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Grand-Total-Sum-SQL/m-p/568851#M160220</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/267062"&gt;@OskarBlad&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;, but if you want to use SQL, you can make the table as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have (drop=i);
	do Groupingvariabel = 'Gruppe1', 'Gruppe2', 'Gruppe3', 'Gruppe4';
		do i = 1 to 10;
			t1 = int(ranuni(3)*100);
			t2 = int(ranuni(3)*100);
			t3 = int(ranuni(3)*100);
			t4 = int(ranuni(3)*100);
			output;
		end;
	end;
run;

proc sql;
	create table want (drop=type) as
		select 
			Groupingvariabel,
			sum(t1) as t1,
			sum(t2) as t2,
			sum(t3) as t3,
			sum(t4) as t4,
			1 as type
		from have
		group by Groupingvariabel
		union
		select
			'Total' as Groupingvariabel,
			sum(t1) as t1,
			sum(t2) as t2,
			sum(t3) as t3,
			sum(t4) as t4,
			2 as type
		from have
		order by 
			type,
			Groupingvariabel;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Jun 2019 16:10:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Grand-Total-Sum-SQL/m-p/568851#M160220</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-06-25T16:10:27Z</dc:date>
    </item>
  </channel>
</rss>

