<?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 PROC EXPORT -- Excel to multiple sheet in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-EXPORT-Excel-to-multiple-sheet/m-p/795506#M255175</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know that this question has been posted several times over the years, but none of the accepted solutions work for me.&lt;/P&gt;
&lt;P&gt;I am trying to create an Excel workbook with three different sheets, from three different datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The documentation for PROC EXPORT says to&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P class="xisDoc-paragraph"&gt;Omit REPLACE and add the new sheet name&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P class="xisDoc-paragraph"&gt;Which I do, and here's my code:&lt;/P&gt;
&lt;P class="xisDoc-paragraph"&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro output_mismatch(outFile=, debug=0);

	%local i lvl;
	
	%do i=1 %to &amp;amp;nlevels.;
		%let lvl=%scan(&amp;amp;geovar., &amp;amp;i.);

		%if %nobs(data=&amp;amp;lvl._mismatch) NE 0 %then %do;
			proc export dbms=xlsx &lt;BR /&gt;                data=&amp;amp;lvl._mismatch(keep=&amp;amp;lvl. rename=(&amp;amp;lvl.=&amp;amp;lvl._uid)) &lt;BR /&gt;                outfile=&amp;amp;outFile.;
				sheet="&amp;amp;lvl.";
			run;
		%end;
	%end;

%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="xisDoc-paragraph"&gt;By checking the log file, I can see that the procedure is executed three times:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: The export data set has 28682 observations and 1 variables.
NOTE: "OUT_MIS" file was successfully created.
NOTE: PROCEDURE EXPORT used (Total process time):
      real time           0.18 seconds
      user cpu time       0.15 seconds
      system cpu time     0.01 seconds
      memory              2900.50k
      OS Memory           34192.00k
      Timestamp           2022-02-10 10:28:00 AM
      Step Count                        314  Switch Count  0

NOTE: The export data set has 1904 observations and 1 variables.
NOTE: "OUT_MIS" file was successfully created.
NOTE: PROCEDURE EXPORT used (Total process time):
      real time           0.04 seconds
      user cpu time       0.01 seconds
      system cpu time     0.00 seconds
      memory              2896.75k
      OS Memory           34192.00k
      Timestamp           2022-02-10 10:28:00 AM
      Step Count                        315  Switch Count  0

NOTE: The export data set has 653 observations and 1 variables.
NOTE: "OUT_MIS" file was successfully created.
NOTE: PROCEDURE EXPORT used (Total process time):
      real time           0.03 seconds
      user cpu time       0.01 seconds
      system cpu time     0.00 seconds
      memory              2898.06k
      OS Memory           34192.00k
      Timestamp           2022-02-10 10:28:00 AM
      Step Count                        316  Switch Count  0
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="xisDoc-paragraph"&gt;But when I open the Excel file, only the last sheet is present, the other two have been overwritten.&lt;BR /&gt;My SAS version is 9.4 M7&lt;/P&gt;</description>
    <pubDate>Thu, 10 Feb 2022 15:31:22 GMT</pubDate>
    <dc:creator>gabonzo</dc:creator>
    <dc:date>2022-02-10T15:31:22Z</dc:date>
    <item>
      <title>PROC EXPORT -- Excel to multiple sheet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-EXPORT-Excel-to-multiple-sheet/m-p/795506#M255175</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know that this question has been posted several times over the years, but none of the accepted solutions work for me.&lt;/P&gt;
&lt;P&gt;I am trying to create an Excel workbook with three different sheets, from three different datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The documentation for PROC EXPORT says to&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P class="xisDoc-paragraph"&gt;Omit REPLACE and add the new sheet name&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P class="xisDoc-paragraph"&gt;Which I do, and here's my code:&lt;/P&gt;
&lt;P class="xisDoc-paragraph"&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro output_mismatch(outFile=, debug=0);

	%local i lvl;
	
	%do i=1 %to &amp;amp;nlevels.;
		%let lvl=%scan(&amp;amp;geovar., &amp;amp;i.);

		%if %nobs(data=&amp;amp;lvl._mismatch) NE 0 %then %do;
			proc export dbms=xlsx &lt;BR /&gt;                data=&amp;amp;lvl._mismatch(keep=&amp;amp;lvl. rename=(&amp;amp;lvl.=&amp;amp;lvl._uid)) &lt;BR /&gt;                outfile=&amp;amp;outFile.;
				sheet="&amp;amp;lvl.";
			run;
		%end;
	%end;

%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="xisDoc-paragraph"&gt;By checking the log file, I can see that the procedure is executed three times:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: The export data set has 28682 observations and 1 variables.
NOTE: "OUT_MIS" file was successfully created.
NOTE: PROCEDURE EXPORT used (Total process time):
      real time           0.18 seconds
      user cpu time       0.15 seconds
      system cpu time     0.01 seconds
      memory              2900.50k
      OS Memory           34192.00k
      Timestamp           2022-02-10 10:28:00 AM
      Step Count                        314  Switch Count  0

NOTE: The export data set has 1904 observations and 1 variables.
NOTE: "OUT_MIS" file was successfully created.
NOTE: PROCEDURE EXPORT used (Total process time):
      real time           0.04 seconds
      user cpu time       0.01 seconds
      system cpu time     0.00 seconds
      memory              2896.75k
      OS Memory           34192.00k
      Timestamp           2022-02-10 10:28:00 AM
      Step Count                        315  Switch Count  0

NOTE: The export data set has 653 observations and 1 variables.
NOTE: "OUT_MIS" file was successfully created.
NOTE: PROCEDURE EXPORT used (Total process time):
      real time           0.03 seconds
      user cpu time       0.01 seconds
      system cpu time     0.00 seconds
      memory              2898.06k
      OS Memory           34192.00k
      Timestamp           2022-02-10 10:28:00 AM
      Step Count                        316  Switch Count  0
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="xisDoc-paragraph"&gt;But when I open the Excel file, only the last sheet is present, the other two have been overwritten.&lt;BR /&gt;My SAS version is 9.4 M7&lt;/P&gt;</description>
      <pubDate>Thu, 10 Feb 2022 15:31:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-EXPORT-Excel-to-multiple-sheet/m-p/795506#M255175</guid>
      <dc:creator>gabonzo</dc:creator>
      <dc:date>2022-02-10T15:31:22Z</dc:date>
    </item>
    <item>
      <title>Re: PROC EXPORT -- Excel to multiple sheet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-EXPORT-Excel-to-multiple-sheet/m-p/795513#M255179</link>
      <description>&lt;P&gt;You don't describe at all why any of the other solutions "don't&amp;nbsp; work for you", or even which solutions you tried.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One thing to remember about Proc Export is that the intent is to create single files. Your log shows you that with each call to the Proc creating the same file name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The LIBNAME XLSX is probably likely the better solution for this.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Feb 2022 16:08:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-EXPORT-Excel-to-multiple-sheet/m-p/795513#M255179</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-02-10T16:08:25Z</dc:date>
    </item>
    <item>
      <title>Re: PROC EXPORT -- Excel to multiple sheet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-EXPORT-Excel-to-multiple-sheet/m-p/795516#M255180</link>
      <description>&lt;P&gt;Forget it, you know what? I have posted the same question three months ago:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Excel-export-to-multiple-sheets-not-working-with-filerefs/m-p/767060" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Excel-export-to-multiple-sheets-not-working-with-filerefs/m-p/767060&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the reason seems to be that PROC EXPORT doesn't work well with file references, but it works if you hardcode the file path.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Feb 2022 16:19:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-EXPORT-Excel-to-multiple-sheet/m-p/795516#M255180</guid>
      <dc:creator>gabonzo</dc:creator>
      <dc:date>2022-02-10T16:19:31Z</dc:date>
    </item>
    <item>
      <title>Re: PROC EXPORT -- Excel to multiple sheet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-EXPORT-Excel-to-multiple-sheet/m-p/796570#M255630</link>
      <description>Known bug: &lt;A href="https://support.sas.com/kb/68/654.html" target="_blank"&gt;https://support.sas.com/kb/68/654.html&lt;/A&gt;</description>
      <pubDate>Wed, 16 Feb 2022 15:03:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-EXPORT-Excel-to-multiple-sheet/m-p/796570#M255630</guid>
      <dc:creator>gabonzo</dc:creator>
      <dc:date>2022-02-16T15:03:58Z</dc:date>
    </item>
  </channel>
</rss>

