<?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 How do I add another worksheet to an existing workbook? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-add-another-worksheet-to-an-existing-workbook/m-p/927608#M365021</link>
    <description>&lt;P&gt;I am running a macro that creates two data sets, I want to output 2 datasets to the same excel worksheet. Then I want to call the macro again and add another worksheet with two datasets to the same workbook. Whenever I run this code, the second run does not add another worksheet. I am wondering what is going on. Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ods excel file='\path'&lt;BR /&gt;options( sheet_interval='NONE' sheet_name="&amp;amp;SCHEMA");&lt;BR /&gt;proc report data=TABLE_DIFF_FINAL;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc report data=VAR_DIFF_FINAL;&lt;BR /&gt;run;&lt;BR /&gt;ods excel close;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 08 May 2024 21:52:45 GMT</pubDate>
    <dc:creator>kyle234</dc:creator>
    <dc:date>2024-05-08T21:52:45Z</dc:date>
    <item>
      <title>How do I add another worksheet to an existing workbook?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-add-another-worksheet-to-an-existing-workbook/m-p/927608#M365021</link>
      <description>&lt;P&gt;I am running a macro that creates two data sets, I want to output 2 datasets to the same excel worksheet. Then I want to call the macro again and add another worksheet with two datasets to the same workbook. Whenever I run this code, the second run does not add another worksheet. I am wondering what is going on. Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ods excel file='\path'&lt;BR /&gt;options( sheet_interval='NONE' sheet_name="&amp;amp;SCHEMA");&lt;BR /&gt;proc report data=TABLE_DIFF_FINAL;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc report data=VAR_DIFF_FINAL;&lt;BR /&gt;run;&lt;BR /&gt;ods excel close;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2024 21:52:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-add-another-worksheet-to-an-existing-workbook/m-p/927608#M365021</guid>
      <dc:creator>kyle234</dc:creator>
      <dc:date>2024-05-08T21:52:45Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add another worksheet to an existing workbook?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-add-another-worksheet-to-an-existing-workbook/m-p/927610#M365023</link>
      <description>&lt;P&gt;Reports are not "data sets", so you are not exporting anything.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When doing things like placing reports into a single spreadsheet file&amp;nbsp; then all of the reports must occur between one ODS Excel file= / ods excel close; "sandwich";&lt;/P&gt;
&lt;P&gt;So remove the ODS EXCEL FILE= part from the macro. You don't show how the "macro" is called so I am guessing but dummy code would look something like&lt;/P&gt;
&lt;PRE&gt;ods excel file=&amp;lt;path&amp;gt; options(any options that apply to whole document&amp;gt;;

%mymacro(schema=firstsheet)

/* to change the sheet you may need to specify an option to force a new sheet*/
ods excel options(sheet_interval='table');
%mymacro(shema=othersheet);

ods excel close;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 May 2024 22:11:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-add-another-worksheet-to-an-existing-workbook/m-p/927610#M365023</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-05-08T22:11:04Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add another worksheet to an existing workbook?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-add-another-worksheet-to-an-existing-workbook/m-p/927611#M365024</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try to add options again with sheet_interval='NOW' option.&lt;/P&gt;
&lt;P&gt;eg.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods excel file='test.xls'
	options( sheet_interval='NONE' sheet_name="class" doc='help');
	proc report data=sashelp.class;
		where sex='F';
	run;
	proc report data=sashelp.class;
		where sex='M';
	run;

	ods excel options( sheet_interval='now' sheet_name="cars");
	proc report data=sashelp.cars;
		where type='SUV';
	run;
	ods excel options( sheet_interval='none');
	proc report data=sashelp.cars;
		where type='Wagon';
	run;
ods excel close;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 May 2024 22:13:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-add-another-worksheet-to-an-existing-workbook/m-p/927611#M365024</guid>
      <dc:creator>A_Kh</dc:creator>
      <dc:date>2024-05-08T22:13:12Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add another worksheet to an existing workbook?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-add-another-worksheet-to-an-existing-workbook/m-p/927613#M365025</link>
      <description>&lt;P&gt;The ODS EXCEL destination doesn't allow for updates to an existing Excel once it got closed. If it's just about adding another data sheet (a table) the libname xlsx engine should work but I wouldn't know how you could add another report.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you can call your macro in the same session then just only open the ODS EXCEL destination once, do all your data processing and reports (can be multiple macro calls) and close the destination at the very end.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If above isn't an option because you want for example to update the Excel only later via a different SAS session then the only approach I can think of is to create separate Excel files and then call some 3rd party product like Python (openxl) or alternatively under Windows some Powershell or VB script out of SAS that copies/moves Excel sheets from one Workbook to another.&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2024 22:21:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-add-another-worksheet-to-an-existing-workbook/m-p/927613#M365025</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-05-08T22:21:07Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add another worksheet to an existing workbook?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-add-another-worksheet-to-an-existing-workbook/m-p/927616#M365027</link>
      <description>&lt;P&gt;There are two way to do that ,but not by "ODS EXCEL".&lt;/P&gt;
&lt;P&gt;But both would not keep the style of data,just put raw data into EXCEL file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) using LIBNAME+XLSX/EXCEL engine&lt;/P&gt;
&lt;P&gt;2)using PROC EXPORT:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc export outfile='c:\temp\test.xlsx' data=sashelp.class dbms=xlsx replace;
sheet='class';
run;
proc export outfile='c:\temp\test.xlsx' data=sashelp.heart dbms=xlsx replace;
sheet='heart';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 May 2024 01:18:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-add-another-worksheet-to-an-existing-workbook/m-p/927616#M365027</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-05-09T01:18:19Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add another worksheet to an existing workbook?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-add-another-worksheet-to-an-existing-workbook/m-p/932618#M366882</link>
      <description>Thank you!</description>
      <pubDate>Mon, 17 Jun 2024 13:26:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-add-another-worksheet-to-an-existing-workbook/m-p/932618#M366882</guid>
      <dc:creator>kyle234</dc:creator>
      <dc:date>2024-06-17T13:26:24Z</dc:date>
    </item>
  </channel>
</rss>

