Hi,
I have 9 segments in my data. For each segment I have 3 scenarios (Base, best and worst) and 3 separate datasets for these scenarios .
I want to generate an excel file with each segment(Seg1, seg2, Seg3---Seg9) as sheet name and 3 tables on each sheet, which means I need an excel file with 9 sheets on it, each sheet having 3 tables.
I need to create a macro for this as I need to make it dynamic.
Thank you for your help.
Satyakshma Rawat
@Satyakshma wrote:
Hi,
I have 9 segments in my data. For each segment I have 3 scenarios (Base, best and worst) and 3 separate datasets for these scenarios .
I want to generate an excel file with each segment(Seg1, seg2, Seg3---Seg9) as sheet name and 3 tables on each sheet, which means I need an excel file with 9 sheets on it, each sheet having 3 tables.
I need to create a macro for this as I need to make it dynamic.
Generally, you can't put three sheets on one table via either PROC EXPORT or ODS EXCEL. You could combine the 3 separate data sets into one, and then put the one big data set on a sheet.
However, aside from that, you can get what you want via ODS EXCEL without macros, using one big data set with a variable indicating segment and the SHEET_INTERVAL='BYGROUP' and SHEET_LABEL='Seg' options.
The following code creates one sheet with three tables:
ods excel file="multi.xlsx" options(sheet_interval= 'none');
proc print data=sashelp.class(obs=3) noobs;
run;
proc print data=sashelp.cars(obs=3) noobs;
run;
proc print data=sashelp.baseball(obs=3) noobs;
run;
ods excel close;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.