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

Hi All,

 

I have a simple proc tabulate and ODS EXCEL to export to MS Excel. The result has a sheet by every segment. 

 

How I configure the ODS Excel statement to have a segment name as sheet name?

 

My current SAS code is:

 

ods excel file="/path/File_Test.xlsx"  options(sheet_interval='page');
    PROC TABULATE DATA=WORK.Test ; 
         CLASS Name Segment  &columnas / ORDER=UNFORMATTED MISSING;
         TABLE Segment, &columnas, Name*ColPctN ;
    RUN;
ods excel close;

But as results each sheet is named: Tabulate 1 - Table 1, Tabulate 2 - Table 1, etc. Please see the attached file.

 

Regards,

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
Diamond | Level 26
Hi, if you switch to BY group processing and use a BY instead of a page, then you can use the #byval for the sheet_name, as shown in this previous posting: https://communities.sas.com/t5/ODS-and-Base-Reporting/ODS-Excelxp-PROC-TABULATE-multiple-sheets/m-p/... -- there is an ODS EXCEL example in the posting on 5-17 that shows using #BYVAL to name the sheets.

cynthia

View solution in original post

3 REPLIES 3
Cynthia_sas
Diamond | Level 26
Hi, if you switch to BY group processing and use a BY instead of a page, then you can use the #byval for the sheet_name, as shown in this previous posting: https://communities.sas.com/t5/ODS-and-Base-Reporting/ODS-Excelxp-PROC-TABULATE-multiple-sheets/m-p/... -- there is an ODS EXCEL example in the posting on 5-17 that shows using #BYVAL to name the sheets.

cynthia
MariaD
Barite | Level 11

Thanks @Cynthia_sas, works perfect!

Reeza
Super User

Try the Sheet_Label and Sheet_name options in the ODS EXCEL statement. 

You can find a lot of examples online using ODS TAGSETS which is the same approach you need for ODS EXCEL.

 

https://support.sas.com/rnd/base/ods/odsmarkup/excelxp_demo.html#data

 

http://documentation.sas.com/?docsetId=odsug&docsetTarget=p09n5pw9ol0897n1qe04zeur27rv.htm&docsetVer...

 

I'm getting some weird behaviour but maybe this will work for you:

 

proc sort data=sashelp.cars out=cars;
by origin;
run;

ods excel file="c:\_localdata\temp.xlsx" options(sheet_interval="bygroup" sheet_label='');

proc print data=cars;
by origin;
run;

ods excel close;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 3 replies
  • 5733 views
  • 0 likes
  • 3 in conversation