<?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: Excel Sheet Names with multiple variables with Proc Freq in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Excel-Sheet-Names-with-multiple-variables-with-Proc-Freq/m-p/617073#M23693</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4357"&gt;@statistician13&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;I am trying to create Excel output with ODS Excel and gain control over the sheet names.&amp;nbsp; The difficulty I'm encountering is that I have a freq procedure (actually the surveyfreq procedure) with multiple variables on the tables statement.&amp;nbsp; This produces one sheet per variable (as I'd hope), but I can't seem to figure out how to control the name of each tab in this case since both tabs are created with the same procedure and I can't use a byvariable as others have suggested using with proc report.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's same sample code:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods excel file="D:\Output1.xls" style=printer;
title "Survey Results";
ods excel options(sheet_name="q0001");
proc surveyfreq data=surveydata missing nosummary;
stratum stratum;
weight FinalWt;
tables cohort*(q0001 q0002)/cl nostd;
run;
quit;
ods excel close;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;As you can see from the tables statement, the output creates two sheets:&amp;nbsp; One for&amp;nbsp;cohort*q0001 and the other for&amp;nbsp;cohort*q0002.&amp;nbsp; Unfortunately, this produces an Excel file with two Sheets named "q0001" and "q0001 2."&amp;nbsp; I'm trying to name the names "q0001" and "q0002" corresponding to the names of the variables.&amp;nbsp; I realize I can do this by breaking out the tables statement into two separate proc freq calls preceded with the ods excel options(sheet_name=&lt;EM&gt;questionname&lt;/EM&gt;) statement, but I'd like to avoid this if possible.&lt;BR /&gt;&lt;BR /&gt;Any suggestions on how to do this?&lt;BR /&gt;&lt;BR /&gt;Thanks.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc surveyfreq creates two separate internal data sets ; one for each table. You can see this if you do:&lt;/P&gt;&lt;P&gt;ods trace on;&lt;/P&gt;&lt;P&gt;before proc surveyfreq;&lt;/P&gt;&lt;P&gt;ods trace off;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can use ODS to grab those data sets and print each one seprately afer your survyefreq procedure. This way you can use sheet_name to name each tab in your excel file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This may not be what you want because it would be equivalent to running two different proc surveyfreqs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dave&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 13 Jan 2020 21:57:06 GMT</pubDate>
    <dc:creator>DWilson</dc:creator>
    <dc:date>2020-01-13T21:57:06Z</dc:date>
    <item>
      <title>Excel Sheet Names with multiple variables with Proc Freq</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Excel-Sheet-Names-with-multiple-variables-with-Proc-Freq/m-p/616841#M23688</link>
      <description>&lt;P&gt;I am trying to create Excel output with ODS Excel and gain control over the sheet names.&amp;nbsp; The difficulty I'm encountering is that I have a freq procedure (actually the surveyfreq procedure) with multiple variables on the tables statement.&amp;nbsp; This produces one sheet per variable (as I'd hope), but I can't seem to figure out how to control the name of each tab in this case since both tabs are created with the same procedure and I can't use a byvariable as others have suggested using with proc report.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's same sample code:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods excel file="D:\Output1.xls" style=printer;
title "Survey Results";
ods excel options(sheet_name="q0001");
proc surveyfreq data=surveydata missing nosummary;
stratum stratum;
weight FinalWt;
tables cohort*(q0001 q0002)/cl nostd;
run;
quit;
ods excel close;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;As you can see from the tables statement, the output creates two sheets:&amp;nbsp; One for&amp;nbsp;cohort*q0001 and the other for&amp;nbsp;cohort*q0002.&amp;nbsp; Unfortunately, this produces an Excel file with two Sheets named "q0001" and "q0001 2."&amp;nbsp; I'm trying to name the names "q0001" and "q0002" corresponding to the names of the variables.&amp;nbsp; I realize I can do this by breaking out the tables statement into two separate proc freq calls preceded with the ods excel options(sheet_name=&lt;EM&gt;questionname&lt;/EM&gt;) statement, but I'd like to avoid this if possible.&lt;BR /&gt;&lt;BR /&gt;Any suggestions on how to do this?&lt;BR /&gt;&lt;BR /&gt;Thanks.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jan 2020 04:49:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Excel-Sheet-Names-with-multiple-variables-with-Proc-Freq/m-p/616841#M23688</guid>
      <dc:creator>statistician13</dc:creator>
      <dc:date>2020-01-13T04:49:01Z</dc:date>
    </item>
    <item>
      <title>Re: Excel Sheet Names with multiple variables with Proc Freq</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Excel-Sheet-Names-with-multiple-variables-with-Proc-Freq/m-p/617073#M23693</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4357"&gt;@statistician13&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;I am trying to create Excel output with ODS Excel and gain control over the sheet names.&amp;nbsp; The difficulty I'm encountering is that I have a freq procedure (actually the surveyfreq procedure) with multiple variables on the tables statement.&amp;nbsp; This produces one sheet per variable (as I'd hope), but I can't seem to figure out how to control the name of each tab in this case since both tabs are created with the same procedure and I can't use a byvariable as others have suggested using with proc report.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's same sample code:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods excel file="D:\Output1.xls" style=printer;
title "Survey Results";
ods excel options(sheet_name="q0001");
proc surveyfreq data=surveydata missing nosummary;
stratum stratum;
weight FinalWt;
tables cohort*(q0001 q0002)/cl nostd;
run;
quit;
ods excel close;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;As you can see from the tables statement, the output creates two sheets:&amp;nbsp; One for&amp;nbsp;cohort*q0001 and the other for&amp;nbsp;cohort*q0002.&amp;nbsp; Unfortunately, this produces an Excel file with two Sheets named "q0001" and "q0001 2."&amp;nbsp; I'm trying to name the names "q0001" and "q0002" corresponding to the names of the variables.&amp;nbsp; I realize I can do this by breaking out the tables statement into two separate proc freq calls preceded with the ods excel options(sheet_name=&lt;EM&gt;questionname&lt;/EM&gt;) statement, but I'd like to avoid this if possible.&lt;BR /&gt;&lt;BR /&gt;Any suggestions on how to do this?&lt;BR /&gt;&lt;BR /&gt;Thanks.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc surveyfreq creates two separate internal data sets ; one for each table. You can see this if you do:&lt;/P&gt;&lt;P&gt;ods trace on;&lt;/P&gt;&lt;P&gt;before proc surveyfreq;&lt;/P&gt;&lt;P&gt;ods trace off;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can use ODS to grab those data sets and print each one seprately afer your survyefreq procedure. This way you can use sheet_name to name each tab in your excel file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This may not be what you want because it would be equivalent to running two different proc surveyfreqs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dave&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jan 2020 21:57:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Excel-Sheet-Names-with-multiple-variables-with-Proc-Freq/m-p/617073#M23693</guid>
      <dc:creator>DWilson</dc:creator>
      <dc:date>2020-01-13T21:57:06Z</dc:date>
    </item>
    <item>
      <title>Re: Excel Sheet Names with multiple variables with Proc Freq</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Excel-Sheet-Names-with-multiple-variables-with-Proc-Freq/m-p/743144#M25013</link>
      <description>&lt;P&gt;I would advise to split the program logic out.&amp;nbsp; Something like three distinct steps&lt;BR /&gt;Get data&lt;/P&gt;
&lt;P&gt;Process data&lt;/P&gt;
&lt;P&gt;Report data&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So in your example, I would process the survey data such that you get a dataset out from it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods output &amp;lt;object&amp;gt;=workingdata;
proc surveyfreq data=surveydata missing nosummary;
stratum stratum;
weight FinalWt;
tables cohort*(q0001 q0002)/cl nostd;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In the above you would need to get the object name from an ods trace on; statement which will show you all the objects which are created (ods trace off; after).&amp;nbsp; The objects can all be saved and processed further - this is a big plus to the process as you can format and manipulate as you want.&lt;/P&gt;
&lt;P&gt;Then when you have the data all nicely processed, then open the Excel ods and report the data.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 May 2021 17:19:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Excel-Sheet-Names-with-multiple-variables-with-Proc-Freq/m-p/743144#M25013</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2021-05-22T17:19:26Z</dc:date>
    </item>
  </channel>
</rss>

