BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ronein
Meteorite | Level 14

Hello

I am using ODS excel to export multiple tables to multiple sheets in one excel file.

I want to create 3 sheets: "one"  "two"   "three".

In the result I get only one sheet.

What is wrong?

 

 

ods excel file="/path/Ex3.XLSX" 
    options(sheet_name="one" sheet_interval='none');
	/*Sheet one*/
	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="two" sheet_interval='none');
	/*Sheet two*/
	Title 'Tables3';
  proc report data=sashelp.prdsale;
    column country region actual predict;
	define country / group page;
	define region / group;
	break after country / summarize page;
  run;
ods excel options(sheet_name="three" sheet_interval='none');
	/*Sheet three*/
  Title 'Table4';
  proc print data=sashelp.heart(obs=10) noobs;
  run;
ods excel close;
  

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ronein
Meteorite | Level 14

I found the solution.

Need to use a dummy table.

I really dont know what this code is doing but it solve the problem and get the desired result

ods excel file="/path/Ex7.XLSX"
    options(sheet_name="Sh1" sheet_interval="none");
/*Sheet1-2 tables*/
	Title 'Table1';
	proc print data=sashelp.class(obs=3) noobs;
	run;
	Title 'Table2';
	proc print data=sashelp.shoes(obs=3) noobs;
	run;
/*Sheet2-multiple tables created by proc report*/
/*Add dummy table */
ods excel options(sheet_interval="table");
ods exclude all;
data _null_;
file print;
put _all_;
run;
ods select all;
ods excel options(sheet_name="Sh2"  sheet_interval="none");
  proc report data=sashelp.prdsale;
    column country region actual predict;
	define country / group page;
	define region / group;
	break after country / summarize page;
  run;
 /*Sheet3-one table*/
/*Add dummy table */
ods excel options(sheet_interval="table");
ods exclude all;
data _null_;
file print;
put _all_;
run;
ods select all;
ods excel options(sheet_name="Sh3"  sheet_interval="none");
  proc print data=sashelp.heart(obs=10) noobs;
  run;
ods excel close;

View solution in original post

8 REPLIES 8
RW9
Diamond | Level 26 RW9
Diamond | Level 26

You have told it not to use multiple sheets with:

sheet_interval='none'

 

Ronein
Meteorite | Level 14

I run this code and still dont get expected result.

In this result each table appear in a different sheet but I want that table+table2 will be in sheet one.

Tables 3 will be in sheet two

Table4 will be in sheet 4

ods excel file="/path/Ex7.XLSX" 
    options(sheet_name="one" );
	/*Sheet one*/
	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="two" );
	/*Sheet two*/
	Title 'Tables3';
  proc report data=sashelp.prdsale;
    column country region actual predict;
	define country / group page;
	define region / group;
	break after country / summarize page;
  run;
ods excel options(sheet_name="three" );
	/*Sheet three*/
  Title 'Table4';
  proc print data=sashelp.heart(obs=10) noobs;
  run;
ods excel close;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Have you tried setting the option at the right moment:

ods excel file="/path/Ex7.XLSX" 
    options(sheet_name="one" sheet_interval="none");
	/*Sheet one*/
	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="two" sheet_interval="table");
	/*Sheet two*/
	Title 'Tables3';
  proc report data=sashelp.prdsale;
    column country region actual predict;
	define country / group page;
	define region / group;
	break after country / summarize page;
  run;
ods excel options(sheet_name="three" sheet_interval="table");
	/*Sheet three*/
  Title 'Table4';
  proc print data=sashelp.heart(obs=10) noobs;
  run;
ods excel close;
Ronein
Meteorite | Level 14

Thank you for your reply.

However, the result of the code that you sent is not giving the desired result.

In this code there are 3 sheets :two   two2  two3  and I want to create one sheet called "two" with 3 tables (from proc report)

 

Joe

 

Ronein
Meteorite | Level 14

I found the solution.

Need to use a dummy table.

I really dont know what this code is doing but it solve the problem and get the desired result

ods excel file="/path/Ex7.XLSX"
    options(sheet_name="Sh1" sheet_interval="none");
/*Sheet1-2 tables*/
	Title 'Table1';
	proc print data=sashelp.class(obs=3) noobs;
	run;
	Title 'Table2';
	proc print data=sashelp.shoes(obs=3) noobs;
	run;
/*Sheet2-multiple tables created by proc report*/
/*Add dummy table */
ods excel options(sheet_interval="table");
ods exclude all;
data _null_;
file print;
put _all_;
run;
ods select all;
ods excel options(sheet_name="Sh2"  sheet_interval="none");
  proc report data=sashelp.prdsale;
    column country region actual predict;
	define country / group page;
	define region / group;
	break after country / summarize page;
  run;
 /*Sheet3-one table*/
/*Add dummy table */
ods excel options(sheet_interval="table");
ods exclude all;
data _null_;
file print;
put _all_;
run;
ods select all;
ods excel options(sheet_name="Sh3"  sheet_interval="none");
  proc print data=sashelp.heart(obs=10) noobs;
  run;
ods excel close;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

The code I presented works perfectly well:

ods excel file="&_sasws_./test.xlsx" options(sheet_name="Sh1" sheet_interval="none");
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_interval="table");
proc print data=sashelp.cars;
run;
ods excel close;

This will print class and shoes to sh1, and cars to sh2 - it is tested working.  Your "Correct" post, does nothing further than what I present here!

Ronein
Meteorite | Level 14

Can you also Add the proc report output to another sheet and check if you get it in one sheet?

 proc report data=sashelp.prdsale;
    column country region actual predict;
	define country / group page;
	define region / group;
	break after country / summarize page;
  run;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

When I run this code:

 

ods excel file="&_sasws_./test.xlsx" options(sheet_name="Sh1" sheet_interval="none");
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_interval="table");
proc print data=sashelp.cars;
run;
proc report data=sashelp.prdsale;
    column country region actual predict;
   define country / group page;
   define region / group;
   break after country / summarize page;
  run;

ods excel close;

I get tabs for Sh1 1 = Class and Shoes,

 

Sh1 2 = Cars

SH1 3-5 = the three summarised tables from the proc report, each on their own tab as three component tables are created - as clearly programmed to do this by the statement:

   break after country / summarize page;

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 20669 views
  • 2 likes
  • 2 in conversation