<?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: proc report - creating custom summary rows in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/proc-report-creating-custom-summary-rows/m-p/666559#M79028</link>
    <description>&lt;P&gt;Going with your Proc SQL approach, I would combine the stats already in the Proc SQL into a single var so Proc REPORT will just do the display.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql;
  create table result as
  select
    "MSRP" as characteristic
    , origin
    , "mean (std)" as value
    , cats(mean(msrp), "(", std(msrp), ")") as cell
  from
    sashelp.cars
  group by
     origin

  union

  select
    "MSRP" as characteristic
    , origin
    , "median (range)" as value
    , cats(median(msrp), "(", catx(" ", min(msrp), max(msrp)), ")") as cell
  from
    sashelp.cars
  group by
    origin
   union
     select
    "MSRP" as characteristic
    , "Total"
    , "mean (std)" as value
    , cats(mean(msrp), "(", std(msrp), ")") as cell
  from
    sashelp.cars

  union

  select
    "MSRP" as characteristic
    , "Total"
    , "median (range)" as value
    , cats(median(msrp), "(", catx(" ", min(msrp), max(msrp)), ")") as cell
  from
    sashelp.cars
  ;
quit;

proc report data=result;
  column characteristic value Origin, cell;
  define characteristic / group ;
  define value / group ;
  define origin / across ;
  define cell / group " " style={textalign=right};
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 02 Jul 2020 08:11:54 GMT</pubDate>
    <dc:creator>BrunoMueller</dc:creator>
    <dc:date>2020-07-02T08:11:54Z</dc:date>
    <item>
      <title>proc report - creating custom summary rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-report-creating-custom-summary-rows/m-p/666044#M79011</link>
      <description>&lt;P&gt;Dear community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been requested to provide a report in which mean, median, max, min and stdev are supposed to be shown in two rows: mean (std) and median(min-max) - and in this format. My existing code relies on having the results in a numeric column, which concatenated statistics are not:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro characteristics_sql_num(total=);
	select "MSRP" length=100 as Characteristics,
		"&amp;amp;summary_function" length=100 label=" " as Value,
		%if %length(&amp;amp;total) GT 0 %then &amp;amp;total as;
	Origin,
		&amp;amp;summary_function(MSRP) format=5.1 as result
		from sashelp.cars
		%if %length(&amp;amp;total) EQ 0 %then group by Origin;
%mend characteristics_sql_num;

%macro characteristics_num;
	%let summary_functions = mean std min median max;

	proc sql;
		create table cars_summary as

			%do i = 1 %to %sysfunc(countw(&amp;amp;summary_functions));
				%let summary_function = %scan(&amp;amp;summary_functions, &amp;amp;i);

				%if &amp;amp;i NE 1 %then
					union;

				%characteristics_sql_num
				union
				%characteristics_sql_num(total="Total")
			%end;
		;
%mend characteristics_num;

%characteristics_num

proc report data=cars_summary;
columns Characteristics Value Origin, result;
define Characteristics -- Value / group;
define Origin / across;
define result / " " format=best6.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I tried inserting the needed rows with break after and compute after, but this unfortunately does not work. Is there a way of generating the needed rows during proc report, or should I rather rebuild my macro to generate the needed concatenations already during proc sql? Thank you for your support in advance.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jun 2020 11:58:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-report-creating-custom-summary-rows/m-p/666044#M79011</guid>
      <dc:creator>js5</dc:creator>
      <dc:date>2020-06-30T11:58:03Z</dc:date>
    </item>
    <item>
      <title>Re: proc report - creating custom summary rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-report-creating-custom-summary-rows/m-p/666399#M79025</link>
      <description>&lt;P&gt;Not knowing how exactly the output needs to look (an example would help very much). Have a look at Proc TABULATE, it allows to have statistics on the row level.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See example below&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc tabulate data=sashelp.cars format=comma14.2;
  class origin;
  var msrp;
  table
    msrp="stats 1"*(mean std)
    msrp="stats 2"*(min median max)
    ,
    origin=" " all
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Jul 2020 14:54:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-report-creating-custom-summary-rows/m-p/666399#M79025</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2020-07-01T14:54:30Z</dc:date>
    </item>
    <item>
      <title>Re: proc report - creating custom summary rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-report-creating-custom-summary-rows/m-p/666557#M79027</link>
      <description>&lt;P&gt;Thanks for responding! Switching to proc tabulate would unfortunately mean rewriting much of the available macros so I am afraid it is not feasible. It would probably be easier to adapt proc sql statements. Below is what I have vs what has been requested:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="numeric_stats.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/46846i094148E02A931AD6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="numeric_stats.png" alt="numeric_stats.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;As I am using ODS excel, maybe there could be a way of putting in a formula which generates the needed format instead of handling it all in proc report?&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jul 2020 07:23:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-report-creating-custom-summary-rows/m-p/666557#M79027</guid>
      <dc:creator>js5</dc:creator>
      <dc:date>2020-07-02T07:23:36Z</dc:date>
    </item>
    <item>
      <title>Re: proc report - creating custom summary rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-report-creating-custom-summary-rows/m-p/666559#M79028</link>
      <description>&lt;P&gt;Going with your Proc SQL approach, I would combine the stats already in the Proc SQL into a single var so Proc REPORT will just do the display.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql;
  create table result as
  select
    "MSRP" as characteristic
    , origin
    , "mean (std)" as value
    , cats(mean(msrp), "(", std(msrp), ")") as cell
  from
    sashelp.cars
  group by
     origin

  union

  select
    "MSRP" as characteristic
    , origin
    , "median (range)" as value
    , cats(median(msrp), "(", catx(" ", min(msrp), max(msrp)), ")") as cell
  from
    sashelp.cars
  group by
    origin
   union
     select
    "MSRP" as characteristic
    , "Total"
    , "mean (std)" as value
    , cats(mean(msrp), "(", std(msrp), ")") as cell
  from
    sashelp.cars

  union

  select
    "MSRP" as characteristic
    , "Total"
    , "median (range)" as value
    , cats(median(msrp), "(", catx(" ", min(msrp), max(msrp)), ")") as cell
  from
    sashelp.cars
  ;
quit;

proc report data=result;
  column characteristic value Origin, cell;
  define characteristic / group ;
  define value / group ;
  define origin / across ;
  define cell / group " " style={textalign=right};
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Jul 2020 08:11:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-report-creating-custom-summary-rows/m-p/666559#M79028</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2020-07-02T08:11:54Z</dc:date>
    </item>
  </channel>
</rss>

