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;
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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.