<?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: Multiple Sheet Output ODS Excel with Proc SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Multiple-Sheet-Output-ODS-Excel-with-Proc-SQL/m-p/846701#M334694</link>
    <description>&lt;P&gt;Easiest way I can think of is to use a macro variable. For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
title "Audi";
select count(*) as Count
	into: count
	from sashelp.cars
	where make='Audi'
;
select &amp;amp;count/count(*) format=percent6.1 as Percent
	from sashelp.cars
;
title "Ford";
select count(*) as Count
	into: count
	from sashelp.cars
	where make='Ford'
;
select &amp;amp;count/count(*) format=percent6.1 as Percent
	from sashelp.cars
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Yields:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="branch"&gt;Audi&lt;BR /&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure SQL: Query Results" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r b header" scope="col"&gt;Count&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;19&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="branch"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="branch"&gt;Audi&lt;BR /&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure SQL: Query Results" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r b header" scope="col"&gt;Percent&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;4.4%&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;BR /&gt;Ford&lt;BR /&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure SQL: Query Results" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r b header" scope="col"&gt;Count&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;23&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ford&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure SQL: Query Results" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r b header" scope="col"&gt;Percent&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;5.4%&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
    <pubDate>Mon, 28 Nov 2022 21:38:39 GMT</pubDate>
    <dc:creator>SASJedi</dc:creator>
    <dc:date>2022-11-28T21:38:39Z</dc:date>
    <item>
      <title>Multiple Sheet Output ODS Excel with Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-Sheet-Output-ODS-Excel-with-Proc-SQL/m-p/846032#M334466</link>
      <description>&lt;P&gt;Currently, I am generating a report on a singular worksheet using ODS Excel Output with Proc Sql steps that all query the same flat file and create about 15 single row "tables" Code example below.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to convert it to a macro that will run all of the same proc sql steps but create unique tabs for each value as assigned from a separate table. When it runs, it either puts all the resulting tables on one tab (if sheet_interval="none") or one proc result on each tab if I specify another option. I want the macro to run all the proc sql steps per the passed value and then create a new worksheet tab with the new passed value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example Code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table PassedValue as&lt;BR /&gt;select distinct PassedValue&lt;BR /&gt;from All_Clients&lt;BR /&gt;order by PassedValue;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ods excel file="file location/File I want.xlsx";&lt;/P&gt;&lt;P&gt;%macro PM_Measure(PassedValue = );&lt;BR /&gt;ods excel options(Sheet_Interval='none' Sheet_Name="&amp;amp;PassedValue." embedded_titles="YES" embedded_footnotes="YES");&lt;/P&gt;&lt;P&gt;title 1 "Title 1";&lt;/P&gt;&lt;P&gt;title3 "Title 3";&lt;/P&gt;&lt;P&gt;footnote2 "footnote 2";&lt;/P&gt;&lt;P&gt;Proc Sql;&lt;/P&gt;&lt;P&gt;select count(Value1)&lt;/P&gt;&lt;P&gt;from All_Clients&lt;/P&gt;&lt;P&gt;where Condition1="YES" and Condition2="YES" and PassedValue="&amp;amp;PassedValue.";&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;....... (14 more versions of similar step)&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;set PassedValue;&lt;BR /&gt;str= catt('%PM_Measure(PassedValue=', PassedValue, ');');&lt;BR /&gt;call execute(str);run;&lt;BR /&gt;ods excel close;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2022 20:58:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-Sheet-Output-ODS-Excel-with-Proc-SQL/m-p/846032#M334466</guid>
      <dc:creator>TylerP8813</dc:creator>
      <dc:date>2022-11-23T20:58:14Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple Sheet Output ODS Excel with Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-Sheet-Output-ODS-Excel-with-Proc-SQL/m-p/846189#M334536</link>
      <description>&lt;P&gt;I'd recommend using SHEET_INTERVAL='PROC' and generating all of the report iterations using a single PROC SQL step. Something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods excel file="file location/File I want.xlsx";
%macro PM_Measure(PassedValue=);
	ods excel options(Sheet_Interval='PROC' Sheet_Name="&amp;amp;PassedValue." 
		embedded_titles="YES" embedded_footnotes="YES");
	proc sql;
		title1 "Title 1";
		title3 "Title 3";
		footnote2 "footnote 2";
		select count(Value1) 
			from All_Clients 
			where Condition1="YES" and Condition2="YES" 
				   and PassedValue="&amp;amp;PassedValue."
		;
	/* 14 more versions of similar step */
	quit;
%mend;
data _null_;
	set PassedValue;
	str=catt('%PM_Measure(PassedValue=', PassedValue, ');');
	call execute(str);
run;
ods excel close;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That should produce a single tab in the Excel workbook for each iteration of the DATA step.&lt;/P&gt;
&lt;P&gt;May the SAS be with you!&lt;BR /&gt;Mark&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Nov 2022 16:24:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-Sheet-Output-ODS-Excel-with-Proc-SQL/m-p/846189#M334536</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2022-11-24T16:24:26Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple Sheet Output ODS Excel with Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-Sheet-Output-ODS-Excel-with-Proc-SQL/m-p/846201#M334546</link>
      <description>&lt;P&gt;NOW + NONE options?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table PassedValue as
select distinct PassedValue
from All_Clients
order by PassedValue;
quit;

 

ods excel file="file location/File I want.xlsx" options(sheet_interval='none');

%macro PM_Measure(PassedValue = );
ods excel options(Sheet_Interval='now' Sheet_Name="&amp;amp;PassedValue." embedded_titles="YES" embedded_footnotes="YES");

title 1 "Title 1";

title3 "Title 3";

footnote2 "footnote 2";

Proc Sql;

select count(Value1)

from All_Clients

where Condition1="YES" and Condition2="YES" and PassedValue="&amp;amp;PassedValue.";

quit;

....... (14 more versions of similar step)

%mend;

 

data _null_;
set PassedValue;
str= catt('%PM_Measure(PassedValue=', PassedValue, ');');
call execute(str);run;
ods excel close;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;LI-SPOILER&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/274272"&gt;@TylerP8813&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Currently, I am generating a report on a singular worksheet using ODS Excel Output with Proc Sql steps that all query the same flat file and create about 15 single row "tables" Code example below.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to convert it to a macro that will run all of the same proc sql steps but create unique tabs for each value as assigned from a separate table. When it runs, it either puts all the resulting tables on one tab (if sheet_interval="none") or one proc result on each tab if I specify another option. I want the macro to run all the proc sql steps per the passed value and then create a new worksheet tab with the new passed value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example Code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table PassedValue as&lt;BR /&gt;select distinct PassedValue&lt;BR /&gt;from All_Clients&lt;BR /&gt;order by PassedValue;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ods excel file="file location/File I want.xlsx";&lt;/P&gt;
&lt;P&gt;%macro PM_Measure(PassedValue = );&lt;BR /&gt;ods excel options(Sheet_Interval='none' Sheet_Name="&amp;amp;PassedValue." embedded_titles="YES" embedded_footnotes="YES");&lt;/P&gt;
&lt;P&gt;title 1 "Title 1";&lt;/P&gt;
&lt;P&gt;title3 "Title 3";&lt;/P&gt;
&lt;P&gt;footnote2 "footnote 2";&lt;/P&gt;
&lt;P&gt;Proc Sql;&lt;/P&gt;
&lt;P&gt;select count(Value1)&lt;/P&gt;
&lt;P&gt;from All_Clients&lt;/P&gt;
&lt;P&gt;where Condition1="YES" and Condition2="YES" and PassedValue="&amp;amp;PassedValue.";&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;....... (14 more versions of similar step)&lt;/P&gt;
&lt;P&gt;%mend;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt;set PassedValue;&lt;BR /&gt;str= catt('%PM_Measure(PassedValue=', PassedValue, ');');&lt;BR /&gt;call execute(str);run;&lt;BR /&gt;ods excel close;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;/LI-SPOILER&gt;</description>
      <pubDate>Thu, 24 Nov 2022 18:08:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-Sheet-Output-ODS-Excel-with-Proc-SQL/m-p/846201#M334546</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-11-24T18:08:45Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple Sheet Output ODS Excel with Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-Sheet-Output-ODS-Excel-with-Proc-SQL/m-p/846690#M334689</link>
      <description>&lt;P&gt;Thanks! Combining it all into one Proc step did the trick!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You wouldn't happen to know an easy way to add in a quick comparison percentage would you? Every first select statement is a numerator and every second select step is a denominator.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Nov 2022 20:52:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-Sheet-Output-ODS-Excel-with-Proc-SQL/m-p/846690#M334689</guid>
      <dc:creator>TylerP8813</dc:creator>
      <dc:date>2022-11-28T20:52:54Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple Sheet Output ODS Excel with Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-Sheet-Output-ODS-Excel-with-Proc-SQL/m-p/846701#M334694</link>
      <description>&lt;P&gt;Easiest way I can think of is to use a macro variable. For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
title "Audi";
select count(*) as Count
	into: count
	from sashelp.cars
	where make='Audi'
;
select &amp;amp;count/count(*) format=percent6.1 as Percent
	from sashelp.cars
;
title "Ford";
select count(*) as Count
	into: count
	from sashelp.cars
	where make='Ford'
;
select &amp;amp;count/count(*) format=percent6.1 as Percent
	from sashelp.cars
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Yields:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="branch"&gt;Audi&lt;BR /&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure SQL: Query Results" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r b header" scope="col"&gt;Count&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;19&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="branch"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="branch"&gt;Audi&lt;BR /&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure SQL: Query Results" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r b header" scope="col"&gt;Percent&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;4.4%&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;BR /&gt;Ford&lt;BR /&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure SQL: Query Results" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r b header" scope="col"&gt;Count&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;23&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ford&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure SQL: Query Results" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r b header" scope="col"&gt;Percent&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;5.4%&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Mon, 28 Nov 2022 21:38:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-Sheet-Output-ODS-Excel-with-Proc-SQL/m-p/846701#M334694</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2022-11-28T21:38:39Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple Sheet Output ODS Excel with Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-Sheet-Output-ODS-Excel-with-Proc-SQL/m-p/846705#M334696</link>
      <description>&lt;P&gt;Ok, so I tried that approach and a few unexpected things happened in my output.&lt;/P&gt;
&lt;P&gt;I put the Numerator and the Denominator each into their own Macro.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For one, I got about the same number of rows for the resultant table that printed out as there are records in the base table (about 7000). Also, the values for each of the two text Macros (Numerator and Denominator) were set to the values from the initial iteration of the report macro and were not overwritten in subsequent iterations of the report macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance for any further help.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Nov 2022 22:22:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-Sheet-Output-ODS-Excel-with-Proc-SQL/m-p/846705#M334696</guid>
      <dc:creator>TylerP8813</dc:creator>
      <dc:date>2022-11-28T22:22:40Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple Sheet Output ODS Excel with Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-Sheet-Output-ODS-Excel-with-Proc-SQL/m-p/846921#M334819</link>
      <description>Nevermind. I was able to use distinct in the select statement to remove the extra rows and a %SYMDEL step at the end of the macro to clear the macro values.</description>
      <pubDate>Tue, 29 Nov 2022 21:08:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-Sheet-Output-ODS-Excel-with-Proc-SQL/m-p/846921#M334819</guid>
      <dc:creator>TylerP8813</dc:creator>
      <dc:date>2022-11-29T21:08:28Z</dc:date>
    </item>
  </channel>
</rss>

