<?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: better code to create report table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/better-code-to-create-report-table/m-p/705025#M216184</link>
    <description>Thanks!&lt;BR /&gt;What is the way to have one total in grand total raw ?&lt;BR /&gt;Now you can see that in last raw it is written 2 times total.&lt;BR /&gt;Thanks&lt;BR /&gt;</description>
    <pubDate>Thu, 10 Dec 2020 12:08:33 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2020-12-10T12:08:33Z</dc:date>
    <item>
      <title>better code to create report table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/better-code-to-create-report-table/m-p/704960#M216151</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;What is the way to create this report and shorted code and more useful way?&lt;/P&gt;
&lt;P&gt;Also in last row (the grand total) it is better that two "total" values will me merged into one "total"&amp;nbsp; cover two fields ("branch" and "status")&lt;/P&gt;
&lt;P&gt;Thanks&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;PRE&gt;&lt;CODE class=" language-sas"&gt;
Data Rawtbl;
input ID branch status Y;
cards;
1 729 1 10
2 729 0 20
3 729 0 30
4 729 0 15
5 836 1 25
6 836 1 50
7 836 1 20
8 836 1 40
9 729 0 40
10 729 0 50
11 836 0 30
12 836 0 80
;
run;


PROC SQL;
	create table t1  as
	select branch,status,
		count(*) as Nr_customers  ,
	       sum(Y) as SUM_Y,
			calculated  SUM_Y/calculated Nr_customers AS AVG_Y
	from  Rawtbl
	group by branch,status
;
QUIT;


PROC SQL;
	create table t2  as
	select status,
		   count(*) as Nr_customers  ,
	       sum(Y) as SUM_Y,
			calculated  SUM_Y/calculated Nr_customers AS AVG_Y
	from  Rawtbl
	group by status
;
QUIT;


PROC SQL;
	create table t3  as
	select  count(*) as Nr_customers  ,
	       sum(Y) as SUM_Y,
			calculated  SUM_Y/calculated Nr_customers AS AVG_Y
	from  Rawtbl
;
QUIT;

Data wanted;
retain branch_char status_char;
set t1 t2 t3;
branch_char=STRIP(put(branch,best12.));
status_char=STRIP(put(status,best12.));

IF branch_char=: '.' then branch_char='Total';
IF status_char=: '.' then status_char='Total';

drop branch status;
rename branch_char=branch  status_char=status;
run;

proc report data=wanted nowd;
column branch status Nr_customers SUM_Y ;
Define branch/display;
Define status/display;
Define Nr_customers/display;
Define SUM_Y/display;
Run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Dec 2020 06:50:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/better-code-to-create-report-table/m-p/704960#M216151</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-12-10T06:50:10Z</dc:date>
    </item>
    <item>
      <title>Re: better code to create report table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/better-code-to-create-report-table/m-p/704971#M216153</link>
      <description>&lt;P&gt;Use next code instead the 3 sql steps.&lt;/P&gt;
&lt;P&gt;I leave to you to create the report from its output:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=rawtbl;
   class branch status;
   var y;
   output out=sums sum=SUM_Y mean=AVG_Y;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;There are more options using PROC SUMMARY or PROC MEANS.&lt;/P&gt;
&lt;P&gt;Check the documentation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Pay attention to next columns:&amp;nbsp; _TYPE_&amp;nbsp; _FREQ_.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2020 07:43:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/better-code-to-create-report-table/m-p/704971#M216153</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-12-10T07:43:57Z</dc:date>
    </item>
    <item>
      <title>Re: better code to create report table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/better-code-to-create-report-table/m-p/704975#M216155</link>
      <description>&lt;P&gt;I don't see AVG_Y in the output at all. Why are you calculating a variable that you don't use afterwards?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=work.rawtbl;
   class branch status;
   var y;
   output out=work.calc(rename=(_freq_=Nr_customers)) sum=sum_y;
run;

proc sort data=work.calc out=work.sorted;
   where _type_ in (0, 1, 3);
   by descending _type_;
run;

proc format;
   value SumLabel
      . = 'Total'
   ;
run;

proc print data=work.sorted;
   format branch status SumLabel.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Dec 2020 08:01:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/better-code-to-create-report-table/m-p/704975#M216155</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-12-10T08:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: better code to create report table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/better-code-to-create-report-table/m-p/705025#M216184</link>
      <description>Thanks!&lt;BR /&gt;What is the way to have one total in grand total raw ?&lt;BR /&gt;Now you can see that in last raw it is written 2 times total.&lt;BR /&gt;Thanks&lt;BR /&gt;</description>
      <pubDate>Thu, 10 Dec 2020 12:08:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/better-code-to-create-report-table/m-p/705025#M216184</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-12-10T12:08:33Z</dc:date>
    </item>
    <item>
      <title>Re: better code to create report table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/better-code-to-create-report-table/m-p/705244#M216294</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks!&lt;BR /&gt;What is the way to have one total in grand total raw ?&lt;BR /&gt;Now you can see that in last raw it is written 2 times total.&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Unfortunately collapsing both cells is not possible. You could replace the format by another data-step - such a step is in the code you have posted. Changing the missing-option to display missing numerics as blank, could help getting what you want:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options missing=' ';

data work.want;
   set work.sorted(rename=(branch = numBranch status = numStatus));
   
   length Branch $ 12 Status $ 1;
   
   Branch = left(put(numBranch, 12.));
   Status = put(numStatus, 1.);
   
   if missing(Status) and not missing(Branch) then Status = 'Total';
   if missing(Branch) then Branch = 'Total';
   
   drop num: _type_;
run;


proc print data=work.want;
   var branch status Nr_Customers sum_y;
run;

options missing='.';&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Dec 2020 06:26:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/better-code-to-create-report-table/m-p/705244#M216294</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-12-11T06:26:26Z</dc:date>
    </item>
  </channel>
</rss>

