BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello

I want to export reports to 4 XLSX sheets.

Sheet1 name is "F"

Sheet2 name is "M"

I want that sheet3 name be "Female"

and sheet4 name be "Male"

However this code provide sheet 3 name "M2" and sheet4 name "M3"

What is the way to  provide sheets names is I ask?

 

 


ods excel file="/usr/local/SAS/SASUsers/LabRet/UserDir/udclk79/_Class_Report_.xlsx" ;
ods excel options (sheet_name='F');
proc report data=sashelp.class;
where sex='F';
column name age height weight;
define name / group;
run;
ods excel options (sheet_name='M');
proc report data=sashelp.class;
where sex='M';
column name age height weight;
define name / group;
run;
ods excel options (sheet_interval='bygroup');
proc sort data=sashelp.class out=class;by sex;Run;
proc report data=class;
by sex;
columns name age height weight ratio;
define name/display;
define age/display;
define weight/display;
define height/display;
define ratio/computed format=percent8.2;
compute ratio;
ratio=height/weight;
endcompute;
run;
ods excel close;

1 REPLY 1
Ksharp
Super User

You need to make a new variable to contain 'Female' and 'Male ' to be used as Sheet name.

 

options nobyline;

ods excel file="c:\temp\_Class_Report_.xlsx" ;
ods excel options (sheet_name='F');
proc report data=sashelp.class;
where sex='F';
column name age height weight;
define name / group;
run;
ods excel options (sheet_name='M');
proc report data=sashelp.class;
where sex='M';
column name age height weight;
define name / group;
run;

proc sort data=sashelp.class out=class;by sex;Run;
data class;set class; _sex=ifc(sex='F','Female','Male  ');run;
ods excel options (sheet_interval='bygroup' sheet_name='#byval1');
proc report data=class;
by _sex;
columns name age height weight ratio;
define name/display;
define age/display;
define weight/display;
define height/display;
define ratio/computed format=percent8.2;
compute ratio;
ratio=height/weight;
endcomp;
run;
ods excel close;

Ksharp_0-1720510235428.png

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

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
  • 1 reply
  • 601 views
  • 1 like
  • 2 in conversation