The SAS Output Delivery System and reporting techniques

ODS Excelxp PROC TABULATE multiple sheets

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 76
Accepted Solution

ODS Excelxp PROC TABULATE multiple sheets

Hi I have

 

PROC TABULATE data=have;

class date var1 var2 var3;

var age;

weight finalwt;

table (all var2),(all var1)*(all var3),date*age*(median);

run;

 

it creates a 'page; for each var2. How can I get each of these 'pages' as a separate sheet in an excel output?

 


Accepted Solutions
Solution
‎05-16-2017 04:51 PM
SAS Super FREQ
Posts: 8,743

Re: ODS Excelxp PROC TABULATE multiple sheets

[ Edited ]

Hi:
We need to see your code, ALL the code that you've tried, including ODS statements.

Using ODS EXCEL (if you have SAS 9.4) to create an .XLSX file or ODS TAGSETS.EXCELXP to create a .XML file are the 2 easiest ways to do what you want. However, you need to tell us how you are currently creating output (your ODS statements) in order to explain.

cynthia

Here's a simple example using SASHELP.SHOES that illustrates using ODS EXCEL:

ods excel file='c:\temp\mult_sheet.xlsx'
    options(sheet_interval='table');
proc tabulate data=sashelp.shoes;
where region in ('Asia', 'Pacific');
 class region product;
 var sales;
 table all region,
       product all,
	   sales*(min mean sum max);
run;
ods excel close;

View solution in original post


All Replies
Solution
‎05-16-2017 04:51 PM
SAS Super FREQ
Posts: 8,743

Re: ODS Excelxp PROC TABULATE multiple sheets

[ Edited ]

Hi:
We need to see your code, ALL the code that you've tried, including ODS statements.

Using ODS EXCEL (if you have SAS 9.4) to create an .XLSX file or ODS TAGSETS.EXCELXP to create a .XML file are the 2 easiest ways to do what you want. However, you need to tell us how you are currently creating output (your ODS statements) in order to explain.

cynthia

Here's a simple example using SASHELP.SHOES that illustrates using ODS EXCEL:

ods excel file='c:\temp\mult_sheet.xlsx'
    options(sheet_interval='table');
proc tabulate data=sashelp.shoes;
where region in ('Asia', 'Pacific');
 class region product;
 var sales;
 table all region,
       product all,
	   sales*(min mean sum max);
run;
ods excel close;
Frequent Contributor
Posts: 76

Re: ODS Excelxp PROC TABULATE multiple sheets

Actually wow, this worked! It  created separate sheets for each 'page'.

 

I think this is the first time I've managed to get something to work first shot in SAS!

Frequent Contributor
Posts: 76

Re: ODS Excelxp PROC TABULATE multiple sheets

Follow up if you don't know: do you think there's a way to name each sheet what the variable in the 'page' group is?

 

For example it's (all sex) so 3 sheets are being properly produced "Tabulate 1 - Table 1"; "Tabulate 2 - Table 1"; "Tabulate 3 - Table 1".

 

Is there a way to get it "All"; "Male"; "Female" (to correspond with the variable values)?

SAS Super FREQ
Posts: 8,743

Re: ODS Excelxp PROC TABULATE multiple sheets

Hi:

  Well, you'll have to generate the "All" table separately and then use BY group processing for the sheet naming,as shown below.

cynthia

Otherwise, you only choice is to macro-ize your program so that you can create 3 tables and use a macro variable for the sheet_name suboption.

 

proc sort data=sashelp.shoes out=twoshoes;
  by region;
  where region in ('Asia', 'Pacific');
run;

ods excel file='c:\temp\mult_sheet2.xlsx'
    options(sheet_interval='table' sheet_name='All');
proc tabulate data=twoshoes;
 class product;
 var sales;
 table product all,
	   sales*(min mean sum max)/ box = 'Asia and Pacific';
run;

options nobyline;
ods excel options(sheet_interval='table' sheet_name='#ByVal1' suppress_bylines='on');
proc tabulate data=twoshoes;
where region in ('Asia', 'Pacific');
by region;
 class region product;
 var sales;
 table product all,
	   sales*(min mean sum max);
run;
 
ods excel close;

here's what the sheets look like:

name_sheets.png

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 212 views
  • 1 like
  • 2 in conversation