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

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?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

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

4 REPLIES 4
Cynthia_sas
SAS Super FREQ

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;
fieldsa83
Quartz | Level 8

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!

fieldsa83
Quartz | Level 8

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)?

Cynthia_sas
SAS Super FREQ

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

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
  • 4 replies
  • 13530 views
  • 5 likes
  • 2 in conversation