<?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: How to create a single file with multiple tabs from tables created from a Macro in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-single-file-with-multiple-tabs-from-tables/m-p/966016#M83974</link>
    <description>&lt;P&gt;You can have more than one TABLE statement in a PROC TABULATE. So it may be possible to have one call to PROC TABULATE produce all of your three desired tables (although I haven't gone through your code carefully enough to be 100% convinced of that), and then the BY variable approach should work.&lt;/P&gt;</description>
    <pubDate>Wed, 07 May 2025 19:23:35 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2025-05-07T19:23:35Z</dc:date>
    <item>
      <title>How to create a single file with multiple tabs from tables created from a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-single-file-with-multiple-tabs-from-tables/m-p/965895#M83966</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;
&lt;P&gt;I am looking for help on a SAS program I have where I run multiple Proc Tabulate analysis for select counties via a macro. I would like to have all proc tabulate outputs for each county in an individual tab named as the county name. Currently it outputs to one tab and it is a lot of data to scroll through all the counties together. Sample data attached.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;options orientation=portrait missing=0;&lt;BR /&gt;ods listing close;&lt;BR /&gt;ods html path="&amp;amp;path" file="&amp;amp;file";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;%macro desc(location);&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;/*YTD TOTALS - COUNTY REPORTS*/&lt;/DIV&gt;
&lt;DIV&gt;title1 "Cases of Disease in &amp;amp;location County, Year Total";&lt;/DIV&gt;
&lt;DIV&gt;proc tabulate data=work.disease2 format=5.;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; where DiagAddress_County = "&amp;amp;location";&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; format sex $sex. evyear evyear. age agegrp. ;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; class evyear age sex / missing preloadfmt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; tables evyear=' '*age=' ' all*evyear=' ',sex=' ' all/printmiss box='Age' rts=25;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; keylabel n=' ' all='Total';&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;proc tabulate data=work.disease2 format=5.;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; where DiagAddress_County = "&amp;amp;location";&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; format sex $sex. evyear evyear. race2 $race. ;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; class evyear race2 sex / missing preloadfmt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; tables evyear=' '*race2=' ' all*evyear=' ',sex=' ' all/printmiss box='Race' rts=25;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; keylabel n=' ' all='Total';&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;proc tabulate data=work.disease2 format=5.;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; where DiagAddress_County = "&amp;amp;location";&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; format sex $sex. evyear evyear. ethnicity2 $ethnic.;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; class evyear ethnicity2 sex / missing preloadfmt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; tables evyear=' '*ethnicity2=' ' all*evyear=' ',sex=' ' all/printmiss box='Ethnicity' rts=25;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; keylabel n=' ' all='Total';&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;proc tabulate data=work.disease2 format=5.;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; where DiagAddress_County = "&amp;amp;location";&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; format sex $sex. evyear evyear. FacilityType $prvtype.;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; class evyear sex / missing preloadfmt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; class FacilityType / order=formatted missing preloadfmt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; tables evyear=' '*FacilityType=' ' all*evyear=' ',sex=' ' all/printmiss box='FacilityType' rts=25;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; keylabel n=' ' all='Total';&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;%mend;&lt;BR /&gt;%desc(CountyA);&lt;BR /&gt;%desc(CountyG);&lt;BR /&gt;%desc(CountyZ);&lt;/DIV&gt;</description>
      <pubDate>Tue, 06 May 2025 18:33:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-single-file-with-multiple-tabs-from-tables/m-p/965895#M83966</guid>
      <dc:creator>mary_mcneill</dc:creator>
      <dc:date>2025-05-06T18:33:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a single file with multiple tabs from tables created from a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-single-file-with-multiple-tabs-from-tables/m-p/965897#M83967</link>
      <description>&lt;P&gt;Use a BY statement, not a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can create the desired Excel tabs, named by the BY variable, with ODS EXCEL and certain options such as SHEET_INTERVAL='BYGROUP' and SHEET_LABEL='byvariablename'&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Example:&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/odsug/p09n5pw9ol0897n1qe04zeur27rv.htm#n0bmw0v2sv7lepn17aovz1217r9k" target="_blank" rel="noopener"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/odsug/p09n5pw9ol0897n1qe04zeur27rv.htm#n0bmw0v2sv7lepn17aovz1217r9k&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 06 May 2025 19:14:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-single-file-with-multiple-tabs-from-tables/m-p/965897#M83967</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-05-06T19:14:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a single file with multiple tabs from tables created from a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-single-file-with-multiple-tabs-from-tables/m-p/965898#M83968</link>
      <description>&lt;P&gt;What do you mean by "multiple tabs" with an ODS HTML output? HTML typically is a single page.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you were sending the output to a spreadsheet, such as with ODS EXCEL, no macro would be needed. You could use BY group processing and an option on the ODS EXCEL statement would name the sheets using the BY values though that would require sorting the data by the variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may also want to consider running this non-macro code and comparing the results:&lt;/P&gt;
&lt;PRE&gt;proc tabulate data=work.disease2 format=5.;
format sex $sex. evyear evyear. age agegrp. ;
class evyear age sex / missing preloadfmt;
class DiagAddress_County;
tables DiagAddress_County='Cases of Disease in' ,
      evyear=' '*age=' ' all*evyear=' ',
      sex=' ' all/printmiss box='Age' rts=25;
keylabel n=' ' all='Total';
run;&lt;/PRE&gt;
&lt;P&gt;I find it helpful to have each dimension of a proc tabulate table on a separate line and indent long dimensions. Above the DiagAddress_County would be a PAGE dimension. If you send the output to ODS EXCEL and use the option sheet_interval='Table' then each table would appear on a separate tab.&lt;/P&gt;</description>
      <pubDate>Tue, 06 May 2025 19:19:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-single-file-with-multiple-tabs-from-tables/m-p/965898#M83968</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2025-05-06T19:19:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a single file with multiple tabs from tables created from a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-single-file-with-multiple-tabs-from-tables/m-p/965919#M83969</link>
      <description>&lt;P&gt;Here is an example. You can start with it. Good Luck.&lt;/P&gt;
&lt;PRE&gt;ods _all_ close;

ods excel file="C:\temp\ABC12.xlsx" options(sheet_name="Sh1" &lt;STRONG&gt;sheet_interval="none"&lt;/STRONG&gt;);
title 'Table1';
proc print data=sashelp.class(obs=3) noobs;
run;
title 'Table2';
proc print data=sashelp.shoes(obs=3) noobs;
run;

ods excel options(sheet_name="Sh2"&lt;STRONG&gt; sheet_interval="now"&lt;/STRONG&gt;); /*This tells SAS to start a new sheet for next PROCs*/
proc print data=sashelp.cars(obs=5);
run;
title 'Table2';
proc print data=sashelp.shoes(obs=3) noobs;
run;
ods excel close;
&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1746582746347.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106769i905CEC1A5310B357/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1746582746347.png" alt="Ksharp_0-1746582746347.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 May 2025 01:52:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-single-file-with-multiple-tabs-from-tables/m-p/965919#M83969</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-05-07T01:52:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a single file with multiple tabs from tables created from a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-single-file-with-multiple-tabs-from-tables/m-p/966008#M83970</link>
      <description>&lt;P&gt;Thanks! I am using a macro to run the same multiple proc tables on only 3 counties out of 88 counties total in my dataset so I thought I would maybe be able to use the same location macro I indicated for the 3 counties to also output the multiple analysis for each county to its own tab in Excel opposed to it outputting all the analysis for the three counties in one tab. I am assuming if I use a By Group with the data set, I will get 88 Tabs, one for each county instead of just the 3 I want, but I'll look into that more &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; I could also possibly just create a new dataset containing only the counties I need the analysis on, and then it might work for just the 3 counties I need it for &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 07 May 2025 18:12:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-single-file-with-multiple-tabs-from-tables/m-p/966008#M83970</guid>
      <dc:creator>mary_mcneill</dc:creator>
      <dc:date>2025-05-07T18:12:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a single file with multiple tabs from tables created from a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-single-file-with-multiple-tabs-from-tables/m-p/966009#M83971</link>
      <description>Just for reference, I am running 67 Proc tabulates for each of the 3 counties which was why I did it with a macro &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Wed, 07 May 2025 18:23:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-single-file-with-multiple-tabs-from-tables/m-p/966009#M83971</guid>
      <dc:creator>mary_mcneill</dc:creator>
      <dc:date>2025-05-07T18:23:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a single file with multiple tabs from tables created from a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-single-file-with-multiple-tabs-from-tables/m-p/966010#M83972</link>
      <description>Just for reference, I am running 67 Proc tabulates for each of the 3 counties (out of 888 total in my dataset) which was why I did it with a macro. If I did it this way, I think I would have to repeat all 67 proc tabulates to indicate when to start a new tab. I was hoping there was a way to utilize the macro (which specifies County=) to tell SAS to run all 67 proc tabulates on the first county and then when it runs it again with the new county, it would output all 67 for the second county in a new tab.</description>
      <pubDate>Wed, 07 May 2025 18:37:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-single-file-with-multiple-tabs-from-tables/m-p/966010#M83972</guid>
      <dc:creator>mary_mcneill</dc:creator>
      <dc:date>2025-05-07T18:37:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a single file with multiple tabs from tables created from a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-single-file-with-multiple-tabs-from-tables/m-p/966016#M83974</link>
      <description>&lt;P&gt;You can have more than one TABLE statement in a PROC TABULATE. So it may be possible to have one call to PROC TABULATE produce all of your three desired tables (although I haven't gone through your code carefully enough to be 100% convinced of that), and then the BY variable approach should work.&lt;/P&gt;</description>
      <pubDate>Wed, 07 May 2025 19:23:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-single-file-with-multiple-tabs-from-tables/m-p/966016#M83974</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-05-07T19:23:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a single file with multiple tabs from tables created from a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-single-file-with-multiple-tabs-from-tables/m-p/966033#M83975</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13026"&gt;@mary_mcneill&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Just for reference, I am running 67 Proc tabulates for each of the 3 counties (out of 888 total in my dataset) which was why I did it with a macro. If I did it this way, I think I would have to repeat all 67 proc tabulates to indicate when to start a new tab. I was hoping there was a way to utilize the macro (which specifies County=) to tell SAS to run all 67 proc tabulates on the first county and then when it runs it again with the new county, it would output all 67 for the second county in a new tab.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In the macro you would be adding two ODS EXCEL options. One to change the sheet interval to something like 'Proc" then another to 'none' (so all the following output is on the same tab) and at that point you could add a SHEET_NAME="&amp;amp;location" (assuming &amp;amp;location is a valid tab name).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that if your 3 tabulates all use the same data set, do not have a variable that changes from Class to Var or vice versa you could use ONE tabulate with 3 Table statements. At which point I would also point out that BY would likely be preferable to WHERE as you could use the Sheet_interval='bygroup'.&lt;/P&gt;</description>
      <pubDate>Thu, 08 May 2025 01:40:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-single-file-with-multiple-tabs-from-tables/m-p/966033#M83975</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2025-05-08T01:40:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a single file with multiple tabs from tables created from a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-single-file-with-multiple-tabs-from-tables/m-p/966068#M83976</link>
      <description>I am in the process of consolidating the proc tabulates that I can; however, since I do have some parameters that change, I am unable to include all 67 tables into one &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; I will try adding the additional ODS EXCEL option</description>
      <pubDate>Thu, 08 May 2025 13:44:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-single-file-with-multiple-tabs-from-tables/m-p/966068#M83976</guid>
      <dc:creator>mary_mcneill</dc:creator>
      <dc:date>2025-05-08T13:44:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a single file with multiple tabs from tables created from a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-single-file-with-multiple-tabs-from-tables/m-p/966088#M83977</link>
      <description>&lt;P&gt;I was able to consolidate the 67 proc statements into two by using multiple Table statements (this SAS program was inherited and needed a good updating!). Unfortunately, I cannot put them all into one because the parameters shift for the other proc statement (the first one looks at the entire year for two years of data and the other looks at a specific timeframe of each year i.e., month-month). I was able to utilize the By Group instead of the macro and it is giving me results for all 3 counties on separate sheets using the code you provided; however&lt;SPAN&gt;, since I have 2 proc statements now, it is giving me 6 sheets (3 for the first proc statement and 3 for the second for each county). Do you know if there is a way for me to get all results from both proc statements to produce 3 sheets instead of 6?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, is there a way to supress ""byvariablename - " from the sheet name when using&amp;nbsp;SHEET_LABEL='byvariablename'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mary_mcneill_0-1746722220093.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106810i37249224F7206E20/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mary_mcneill_0-1746722220093.png" alt="mary_mcneill_0-1746722220093.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 May 2025 16:41:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-single-file-with-multiple-tabs-from-tables/m-p/966088#M83977</guid>
      <dc:creator>mary_mcneill</dc:creator>
      <dc:date>2025-05-08T16:41:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a single file with multiple tabs from tables created from a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-single-file-with-multiple-tabs-from-tables/m-p/966089#M83978</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;EM&gt;Do you know if there is a way for me to get all results from both proc statements to produce 3 sheets instead of 6?&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I'm guessing this takes us back to the macro solution.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 08 May 2025 16:44:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-a-single-file-with-multiple-tabs-from-tables/m-p/966089#M83978</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-05-08T16:44:19Z</dc:date>
    </item>
  </channel>
</rss>

