<?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: export multiple data sets into multiple sheets in excel in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/export-multiple-data-sets-into-multiple-sheets-in-excel/m-p/677185#M204260</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/****Way1-Export 3 data sets to 3 excel sheets***/
/****Way1-Export 3 data sets to 3 excel sheets***/ 
/****Way1-Export 3 data sets to 3 excel sheets***/
PROC EXPORT DATA=sashelp.cars (where=(Origin="USA"))
  outfile= "/path/Way1.xlsx"
  dbms=xlsx;
  sheet="USA";
run;
 PROC EXPORT DATA=sashelp.cars (where=(Origin="Europe"))
  outfile= "/path/Way1.xlsx"
  dbms=xlsx;
  sheet="Europe";
run;
 PROC EXPORT DATA=sashelp.cars (where=(Origin="Asia"))
  outfile= "/path/Way1.xlsx"
  dbms=xlsx;
  sheet="Asia";
run;


/****Way2-Export 3 data sets to 3 excel sheets***/
/****Way2-Export 3 data sets to 3 excel sheets***/ 
/****Way2-Export 3 data sets to 3 excel sheets***/
ods _all_ close;
ods excel file="/path/Way2.xlsx";
proc report data=sashelp.cars (where=(Origin="USA"));
columns _all_;
run;

proc report data=sashelp.cars (where=(Origin="Europe"));
columns _all_;
run;

proc report data=sashelp.cars (where=(Origin="Asia"));
columns _all_;
run;
ods excel close;
/*Question: How to control sheet name????*/
/*Question: How to create 3 sheets????*/



/****Way3-Export 3 data sets to 3 excel sheets***/
/****Way3-Export 3 data sets to 3 excel sheets***/ 
/****Way3-Export 3 data sets to 3 excel sheets***/
PROC EXPORT DATA=sashelp.cars (where=(Origin="USA"))
  outfile= "/path/Way3.csv"
  dbms=csv;
  sheet="USA";
run;
 PROC EXPORT DATA=sashelp.cars (where=(Origin="Europe"))
  outfile= "/path/Way3.csv"
  dbms=csv;
  sheet="Europe";
run;
 PROC EXPORT DATA=sashelp.cars (where=(Origin="Asia"))
  outfile= "/path/Way3.csv"
  dbms=csv;
  sheet="Asia";
run;
/***Is it possible to  create multiple sheets in CSV file??????**/


 

/****Way4-Export 3 data sets to 3 excel sheets***/
/****Way4-Export 3 data sets to 3 excel sheets***/ 
/****Way4-Export 3 data sets to 3 excel sheets***/
ods _all_ close;/*To prevent print on screen*/

ods path work.temptemp(update) sasuser.templat(update) sashelp.tmplmst(read); 
ods path show; 

ods tagsets.excelxp file= "/path/Way4.XLS" style=htmlblue;
 
ods tagsets.excelxp options(embedded_titles='yes' sheet_interval='none' sheet_name='USA');
proc print data=sashelp.cars (where=(Origin="USA"))  noobs label;
run;
 
ods tagsets.excelxp options(embedded_titles='yes' sheet_interval='none' sheet_name='Europe');
proc print data=sashelp.cars (where=(Origin="Europe"))  noobs label;
run;
 
ods tagsets.excelxp options(embedded_titles='yes' sheet_interval='none' sheet_name='Asia');
proc print data=sashelp.cars (where=(Origin="Asia"))  noobs label;
run;
 
ods tagsets.excelxp close;
ods _all_ close;
 


/****Way5-Export 3 data sets to 3 excel sheets***/
/****Way5-Export 3 data sets to 3 excel sheets***/
/****Way5-Export 3 data sets to 3 excel sheets***/
/*XLSX engine libname*/
libname RRR xlsx "/path/Way5.xlsx";
data RRR.asia;
 set sashelp.cars (where=(Origin='Asia'));
run;
data RRR.usa;
 set sashelp.cars (where=(Origin='USA'));
run;
data RRR.Europe;
set sashelp.cars (where=(Origin='Europe'));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 17 Aug 2020 12:16:10 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2020-08-17T12:16:10Z</dc:date>
    <item>
      <title>export multiple data sets into multiple sheets in excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/export-multiple-data-sets-into-multiple-sheets-in-excel/m-p/677181#M204257</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have a big data set with 1 million rows.&lt;/P&gt;
&lt;P&gt;I need to export it to multiple sheets in Excel file (By value of group variable).&lt;/P&gt;
&lt;P&gt;What is the best way to do it?&lt;/P&gt;
&lt;P&gt;Is it possible to create CSV file with multiple sheets?&lt;/P&gt;
&lt;P&gt;The users should use it in Excel so any format that applicable in excel is okay: XMLS, CSV, or another format&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Aug 2020 12:12:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/export-multiple-data-sets-into-multiple-sheets-in-excel/m-p/677181#M204257</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-08-17T12:12:34Z</dc:date>
    </item>
    <item>
      <title>Re: export multiple data sets into multiple sheets in excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/export-multiple-data-sets-into-multiple-sheets-in-excel/m-p/677184#M204259</link>
      <description>&lt;P&gt;You can use ODS EXCEL with the option SHEET_INTERVAL='BYGROUP'&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sashelp.class out=class;
    by sex;
run;
ods excel file="d:\myfolder\class.xlsx" options(sheet_interval='BYGROUP');
proc print data=class;
    by sex;
run;
ods excel close;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;There is no such thing as a CSV with multiple sheets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Editor's note: Thanks for PaigeMiller's answer and Reeza's additional context on sheet_name.&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Jul 2022 20:49:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/export-multiple-data-sets-into-multiple-sheets-in-excel/m-p/677184#M204259</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-07-01T20:49:14Z</dc:date>
    </item>
    <item>
      <title>Re: export multiple data sets into multiple sheets in excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/export-multiple-data-sets-into-multiple-sheets-in-excel/m-p/677185#M204260</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/****Way1-Export 3 data sets to 3 excel sheets***/
/****Way1-Export 3 data sets to 3 excel sheets***/ 
/****Way1-Export 3 data sets to 3 excel sheets***/
PROC EXPORT DATA=sashelp.cars (where=(Origin="USA"))
  outfile= "/path/Way1.xlsx"
  dbms=xlsx;
  sheet="USA";
run;
 PROC EXPORT DATA=sashelp.cars (where=(Origin="Europe"))
  outfile= "/path/Way1.xlsx"
  dbms=xlsx;
  sheet="Europe";
run;
 PROC EXPORT DATA=sashelp.cars (where=(Origin="Asia"))
  outfile= "/path/Way1.xlsx"
  dbms=xlsx;
  sheet="Asia";
run;


/****Way2-Export 3 data sets to 3 excel sheets***/
/****Way2-Export 3 data sets to 3 excel sheets***/ 
/****Way2-Export 3 data sets to 3 excel sheets***/
ods _all_ close;
ods excel file="/path/Way2.xlsx";
proc report data=sashelp.cars (where=(Origin="USA"));
columns _all_;
run;

proc report data=sashelp.cars (where=(Origin="Europe"));
columns _all_;
run;

proc report data=sashelp.cars (where=(Origin="Asia"));
columns _all_;
run;
ods excel close;
/*Question: How to control sheet name????*/
/*Question: How to create 3 sheets????*/



/****Way3-Export 3 data sets to 3 excel sheets***/
/****Way3-Export 3 data sets to 3 excel sheets***/ 
/****Way3-Export 3 data sets to 3 excel sheets***/
PROC EXPORT DATA=sashelp.cars (where=(Origin="USA"))
  outfile= "/path/Way3.csv"
  dbms=csv;
  sheet="USA";
run;
 PROC EXPORT DATA=sashelp.cars (where=(Origin="Europe"))
  outfile= "/path/Way3.csv"
  dbms=csv;
  sheet="Europe";
run;
 PROC EXPORT DATA=sashelp.cars (where=(Origin="Asia"))
  outfile= "/path/Way3.csv"
  dbms=csv;
  sheet="Asia";
run;
/***Is it possible to  create multiple sheets in CSV file??????**/


 

/****Way4-Export 3 data sets to 3 excel sheets***/
/****Way4-Export 3 data sets to 3 excel sheets***/ 
/****Way4-Export 3 data sets to 3 excel sheets***/
ods _all_ close;/*To prevent print on screen*/

ods path work.temptemp(update) sasuser.templat(update) sashelp.tmplmst(read); 
ods path show; 

ods tagsets.excelxp file= "/path/Way4.XLS" style=htmlblue;
 
ods tagsets.excelxp options(embedded_titles='yes' sheet_interval='none' sheet_name='USA');
proc print data=sashelp.cars (where=(Origin="USA"))  noobs label;
run;
 
ods tagsets.excelxp options(embedded_titles='yes' sheet_interval='none' sheet_name='Europe');
proc print data=sashelp.cars (where=(Origin="Europe"))  noobs label;
run;
 
ods tagsets.excelxp options(embedded_titles='yes' sheet_interval='none' sheet_name='Asia');
proc print data=sashelp.cars (where=(Origin="Asia"))  noobs label;
run;
 
ods tagsets.excelxp close;
ods _all_ close;
 


/****Way5-Export 3 data sets to 3 excel sheets***/
/****Way5-Export 3 data sets to 3 excel sheets***/
/****Way5-Export 3 data sets to 3 excel sheets***/
/*XLSX engine libname*/
libname RRR xlsx "/path/Way5.xlsx";
data RRR.asia;
 set sashelp.cars (where=(Origin='Asia'));
run;
data RRR.usa;
 set sashelp.cars (where=(Origin='USA'));
run;
data RRR.Europe;
set sashelp.cars (where=(Origin='Europe'));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Aug 2020 12:16:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/export-multiple-data-sets-into-multiple-sheets-in-excel/m-p/677185#M204260</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-08-17T12:16:10Z</dc:date>
    </item>
    <item>
      <title>Re: export multiple data sets into multiple sheets in excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/export-multiple-data-sets-into-multiple-sheets-in-excel/m-p/677264#M204274</link>
      <description>&lt;P&gt;If you are using arbitrary procs to generate output for a single ODS Excel destination then you set the SHEET_NAME and SHEET_INTERVAL in a ods excel options before each procedure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;ods excel file="/path/Way2.xlsx" options(sheet_interval="PROC");

ods excel options(sheet_name="USA");
proc report data=sashelp.cars (where=(Origin="USA"));
columns _all_;
run;

ods excel options(sheet_name="Europe");
proc report data=sashelp.cars (where=(Origin="Europe"));
columns _all_;
run;

ods excel options(sheet_name="Asia");
proc report data=sashelp.cars (where=(Origin="Asia"));
columns _all_;
run;
ods excel close;&lt;/PRE&gt;
&lt;P&gt;The SHEET_INTERVAL here means each procedure generates a single "tab" of output, there are other options, Read the Friendly Manual; then Sheet_name before each step that generated ODS output sets the name of the sheet (Data steps can create ODS output ). The SHEET_LABEL option can also affect the names of the sheets. There are interactions between these three options that are not going to be answered in a short paragraph.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Aug 2020 14:58:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/export-multiple-data-sets-into-multiple-sheets-in-excel/m-p/677264#M204274</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-08-17T14:58:43Z</dc:date>
    </item>
    <item>
      <title>Re: export multiple data sets into multiple sheets in excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/export-multiple-data-sets-into-multiple-sheets-in-excel/m-p/677337#M204295</link>
      <description>&lt;P&gt;WAY3 is not correct and will not work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;WAY4 is outdated and generates an XML file that causes an issue within Excel so you should really be using ODS EXCEL instead, if you have 9.4M3+ (M4 is my recommendation, M3 is still buggy).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC COPY is another method with the libname option, especially if you have the three data sets already split.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;is the simplest so far as all your other options are not dynamic - if you add another origin group the code will fail. You can control the name of the sheet with other options - sheet_label for example.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Aug 2020 19:36:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/export-multiple-data-sets-into-multiple-sheets-in-excel/m-p/677337#M204295</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-08-17T19:36:49Z</dc:date>
    </item>
    <item>
      <title>Re: export multiple data sets into multiple sheets in excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/export-multiple-data-sets-into-multiple-sheets-in-excel/m-p/677338#M204296</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;WAY3 is not correct and will not work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;WAY4 is outdated and generates an XML file that causes an issue within Excel so you should really be using ODS EXCEL instead, if you have 9.4M3+ (M4 is my recommendation, M3 is still buggy).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC COPY is another method with the libname option, especially if you have the three data sets already split.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;is the simplest so far as all your other options are not dynamic - if you add another origin group the code will fail. You can control the name of the sheet with other options - sheet_label for example.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, SAS has already done the hard work to make the code dynamic, and so that it works on whatever BY group values are in the data set.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Aug 2020 19:59:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/export-multiple-data-sets-into-multiple-sheets-in-excel/m-p/677338#M204296</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-17T19:59:22Z</dc:date>
    </item>
    <item>
      <title>Re: export multiple data sets into multiple sheets in excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/export-multiple-data-sets-into-multiple-sheets-in-excel/m-p/677340#M204298</link>
      <description>&lt;P&gt;Yup. And you can control the labels on the page name by using the &lt;STRONG&gt;SHEET_NAME&lt;/STRONG&gt; option and specifying the &lt;STRONG&gt;#byval1&lt;/STRONG&gt;. This works with either PROC REPORT or PRINT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods excel file="/home/fkhurshed/my_courses/cars.xlsx" options(sheet_interval='BYGROUP' sheet_name= '#byval1');
proc print data=cars;
by origin;
run;
ods excel close;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Aug 2020 20:07:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/export-multiple-data-sets-into-multiple-sheets-in-excel/m-p/677340#M204298</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-08-17T20:07:13Z</dc:date>
    </item>
    <item>
      <title>Re: export multiple data sets into multiple sheets in excel</title>
      <link>https://communities.sas.com/t5/SAS-Programming/export-multiple-data-sets-into-multiple-sheets-in-excel/m-p/758713#M239616</link>
      <description>&lt;P&gt;This is probably the cleanest and easiest-to-understand codeS I have ever seen!!!&lt;/P&gt;&lt;P&gt;I would love to learn more from you about how to become a better coder using SAS&lt;/P&gt;</description>
      <pubDate>Mon, 02 Aug 2021 07:01:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/export-multiple-data-sets-into-multiple-sheets-in-excel/m-p/758713#M239616</guid>
      <dc:creator>mss2am</dc:creator>
      <dc:date>2021-08-02T07:01:34Z</dc:date>
    </item>
  </channel>
</rss>

