<?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: applying completerows only to certain group variables in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/applying-completerows-only-to-certain-group-variables/m-p/623539#M23761</link>
    <description>&lt;P&gt;I was able to almost get the desired results by switching to proc tabulate and doing a data step to generate classdata dataset:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cars_summary_classdata;
	set cars_summary;
	by Type Origin Make;

	if first.Make then
		do DriveTrain="Total", "All", "Front", "Rear";
			output;
		end;
run;

proc tabulate data=cars_summary order=data classdata=cars_summary_classdata exclusive;
	class Type Origin Make DriveTrain / preloadfmt;
	var cars;

	table Origin*Make*DriveTrain, Type*cars;
		format Origin $origin. Make $make. DriveTrain $trivetrain. Type $type.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Only two issues remain:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Exporting proc tabulate output to excel via ods leads to numbers being stored as text. This makes the excel less usable in comparison to when proc report is used&lt;/LI&gt;&lt;LI&gt;Is there a way to make proc tabulate not calculate the statistic?, By default sum is computed which necessitates re-applying the format&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
    <pubDate>Mon, 10 Feb 2020 10:33:27 GMT</pubDate>
    <dc:creator>js5</dc:creator>
    <dc:date>2020-02-10T10:33:27Z</dc:date>
    <item>
      <title>applying completerows only to certain group variables</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/applying-completerows-only-to-certain-group-variables/m-p/622645#M23753</link>
      <description>&lt;P&gt;Dear community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to generate the report which shows all categories for a group variable, even if no events fit the category. I have managed to build a reproducer using sashelp.cars:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro cars_counter(type_total=, drivetrain_total=, make_total=, origin_total=);
		select %if %length(&amp;amp;type_total) GT 0 %then &amp;amp;type_total as ;Type,
			%if %length(&amp;amp;origin_total) GT 0 %then &amp;amp;origin_total as ;Origin,
			%if %length(&amp;amp;make_total) GT 0 %then &amp;amp;make_total as ; Make,
			%if %length(&amp;amp;drivetrain_total) GT 0 %then &amp;amp;drivetrain_total as ; DriveTrain,
			count(distinct Model) as cars
		from sashelp.cars
					group by 1 /* fake group to simplify concatenation */
						%if %length(&amp;amp;type_total) EQ 0 %then ,Type;
						%if %length(&amp;amp;origin_total) EQ 0 %then ,Origin;
						%if %length(&amp;amp;make_total) EQ 0 %then ,Make;
						%if %length(&amp;amp;drivetrain_total) EQ 0 %then ,DriveTrain;

%mend cars_counter;
%macro cars_report;
proc sql;
create table cars_summary as 
%do i = 1 %to 2;
	%do j = 1 %to 2;
		%do k = 1 %to 2;
			%cars_counter(
				type_total=%scan(|"Total", &amp;amp;i, |),
				drivetrain_total=%scan(|"Total", &amp;amp;j, |),
				make_total=%scan(|"Total", &amp;amp;k, |)
				)
				union
		%end;
	%end;

	%cars_counter(
		type_total=%scan(|"Total", &amp;amp;i, |),
		drivetrain_total="Total",
		make_total="Total",
		origin_total="Total"
		)
		%if %eval(&amp;amp;i + &amp;amp;j + &amp;amp;k) LT 8 %then union;
%end;
;
%mend cars_report;

%cars_report

proc format;
	value $type(notsorted)
		"Hybrid"	= "Hybrid"
		"SUV"		= "SUV"
		"Sedan"		= "Sedan"
		"Sports"	= "Sports"
		"Truck"		= "Truck"
		"Wagon"		= "Wagon"
		"Total"		= "Total";
	value $origin(notsorted default=10)
		"Total" = "Total";
	value $make(notsorted default=10)
		"Total" = "Total";
	value $drivetrain(notsorted default=10)
		"Total" = "Total"
		"All"	= "All"
		"Front"	= "Front"
		"Rear"	= "Rear";
run;

proc report data=cars_summary;
	columns Origin Make DriveTrain Type, cars;
	define Origin / group format=$origin. preloadfmt order=data;
	define Make / group format=$make. preloadfmt order=data;
	define DriveTrain / group format=$drivetrain. preloadfmt order=data;
	define Type / "" across format=$type. preloadfmt order=data;
	define cars / " ";
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I add completerows to the proc report statement, I get all combinations of origins and makes in addition to all drivetrain versions. What I would like to show all drivetrains for all makes, but only show the makes for the origins which are present in the input dataset. In other words, I would like to have Front and Rear displayed for Land Rover, but without Land Rover being displayed in Asia and USA.&lt;/P&gt;&lt;P&gt;I tried experimenting with nozero and exclusive options but without success so far. Thank you for your support in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Feb 2020 10:13:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/applying-completerows-only-to-certain-group-variables/m-p/622645#M23753</guid>
      <dc:creator>js5</dc:creator>
      <dc:date>2020-02-06T10:13:58Z</dc:date>
    </item>
    <item>
      <title>Re: applying completerows only to certain group variables</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/applying-completerows-only-to-certain-group-variables/m-p/622747#M23754</link>
      <description>HI: Unfortunately, COMPLETEROWS applies to ALL the GROUP or ORDER variables. It's not clear to me what you want. Do you want FRONT and REAR to also be displayed for other cars that don't have that type of drivetrain? For example, Hyundai is in Asia and only has Front drivetrain value. Land Rover is in Europe and only has ALL drivetrain value. If you want to see Front and Rear for Land Rover, do you also want to see All and Rear for Hyundai???&lt;BR /&gt;&lt;BR /&gt;  You might get farther with TABULATE and using CLASSDATA and EXCLUSIVE. &lt;BR /&gt;&lt;BR /&gt;But I'm not entirely sure of your reason for pre-summarizing the data and adding TOTAL rows.&lt;BR /&gt;&lt;BR /&gt;Cynthia</description>
      <pubDate>Thu, 06 Feb 2020 15:54:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/applying-completerows-only-to-certain-group-variables/m-p/622747#M23754</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2020-02-06T15:54:08Z</dc:date>
    </item>
    <item>
      <title>Re: applying completerows only to certain group variables</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/applying-completerows-only-to-certain-group-variables/m-p/622756#M23755</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;yes, I would like all drivetrain types to be displayed for all car makes - so I would also like to see All and Rear for Huyndai.&lt;/P&gt;&lt;P&gt;The reason I am pre-summarising the data is due to the fact that with my real data I need to apply and additional condition to the total across types, and also due to the fact that I need to calculate frequencies which have a different denominator depending on whether it is the total or an individual type. As far as I am aware there is no way of doing it with a single proc report pass. I also only need some of the totals, not all 8 combinations.&lt;/P&gt;&lt;P&gt;Thanks for the tip, I will try tabulate. My initial experience with reporting was with proc tabulate, but I then switched to proc report as it seemed more flexible. Looks like both have their strengths.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Feb 2020 16:13:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/applying-completerows-only-to-certain-group-variables/m-p/622756#M23755</guid>
      <dc:creator>js5</dc:creator>
      <dc:date>2020-02-06T16:13:07Z</dc:date>
    </item>
    <item>
      <title>Re: applying completerows only to certain group variables</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/applying-completerows-only-to-certain-group-variables/m-p/622757#M23756</link>
      <description>&lt;P&gt;You might look into the PRELOADFMT option for the variables that you want all values for and not use the COMPLETEROWS option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Preloadfmt would require you to make a format with the desired values to display and then use the format along with Preloadfmt and order=data in the define statement for the variable.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Feb 2020 16:13:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/applying-completerows-only-to-certain-group-variables/m-p/622757#M23756</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-02-06T16:13:38Z</dc:date>
    </item>
    <item>
      <title>Re: applying completerows only to certain group variables</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/applying-completerows-only-to-certain-group-variables/m-p/623539#M23761</link>
      <description>&lt;P&gt;I was able to almost get the desired results by switching to proc tabulate and doing a data step to generate classdata dataset:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cars_summary_classdata;
	set cars_summary;
	by Type Origin Make;

	if first.Make then
		do DriveTrain="Total", "All", "Front", "Rear";
			output;
		end;
run;

proc tabulate data=cars_summary order=data classdata=cars_summary_classdata exclusive;
	class Type Origin Make DriveTrain / preloadfmt;
	var cars;

	table Origin*Make*DriveTrain, Type*cars;
		format Origin $origin. Make $make. DriveTrain $trivetrain. Type $type.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Only two issues remain:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Exporting proc tabulate output to excel via ods leads to numbers being stored as text. This makes the excel less usable in comparison to when proc report is used&lt;/LI&gt;&lt;LI&gt;Is there a way to make proc tabulate not calculate the statistic?, By default sum is computed which necessitates re-applying the format&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 10 Feb 2020 10:33:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/applying-completerows-only-to-certain-group-variables/m-p/623539#M23761</guid>
      <dc:creator>js5</dc:creator>
      <dc:date>2020-02-10T10:33:27Z</dc:date>
    </item>
    <item>
      <title>Re: applying completerows only to certain group variables</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/applying-completerows-only-to-certain-group-variables/m-p/623623#M23762</link>
      <description>&lt;P&gt;Hi:&lt;BR /&gt;&amp;nbsp; How did you export the PROC TABULATE to Excel -- using ODS EXCEL or ODS TAGSETS.EXCELXP or ODS CSV? You didn't show any ODS statements in your code. PROC TABULATE always uses a statistic either N for CLASS variables or SUM for numeric variables. So when you have TYPE*CARS, the implicit statistic is as though you had typed TYPE*CARS*SUM. &lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; You can use a style override to impact the format in EXCEL if you are using ODS EXCEL or ODS TAGSETS.EXCELXP. You can't use a style override with ODS CSV.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; But I don't observe any numbers stored as text when I use either ODS EXCEL or ODS TAGSETS.EXCELXP, see the example below:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tab_classdata_exclusive.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/35979i4D1F8AB5317375EC/image-size/large?v=v2&amp;amp;px=999" role="button" title="tab_classdata_exclusive.png" alt="tab_classdata_exclusive.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The only difference I see is the treatment of decimal places in the destination output.&lt;BR /&gt;&lt;BR /&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Mon, 10 Feb 2020 17:06:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/applying-completerows-only-to-certain-group-variables/m-p/623623#M23762</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2020-02-10T17:06:46Z</dc:date>
    </item>
    <item>
      <title>Re: applying completerows only to certain group variables</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/applying-completerows-only-to-certain-group-variables/m-p/623784#M23765</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This code results in numbers being stored as text:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods excel file="c:\users\&amp;amp;sysuserid\Work FOlders\Desktop\ods_test.xlsx" options(flow="tables");
proc tabulate data=cars_summary order=data classdata=cars_summary_classdata exclusive;
	class Type Origin Make DriveTrain / preloadfmt;
	var cars;

	table Origin*Make*DriveTrain, Type*cars*f=3.;
		format Origin $origin. Make $make. DriveTrain $drivetrain. Type $type.;
run;
ods excel close;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In looks like changing the format of the sum is the culprit.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2020 08:39:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/applying-completerows-only-to-certain-group-variables/m-p/623784#M23765</guid>
      <dc:creator>js5</dc:creator>
      <dc:date>2020-02-11T08:39:20Z</dc:date>
    </item>
  </channel>
</rss>

