Hello,
I want to export from SAS to Excel in the following way:
One sheet for Males (source data sashelp.class)
One sheet for Females (source data sashelp.class)
One sheet for Acura Cars ( (Source data sashelp.cars)
One sheet for Sedan and Sports cars with separate table (Source data sashelp.cars)
May anyone show how to do it please?
Please note that for sheet male and sheet female I have used sheet_interval='BYGROUP' option.
The problem is how to add other elements of export
thanks
proc sort data=sashelp.class out=class;
by sex;
run;
ods excel file= "/path/ReportX.xlsx"
options(sheet_interval='BYGROUP' sheet_name= '#byval1');
/***Each Sex has a different sheet**/
proc print data=class;
by sex;
run;
/***Export to another sheet called 'Acura_Cars'***/
Title 'Acura Cars';
proc print data=sashelp.cars noobs;
where make='Acura';
Run;
/***Export to another sheet called 'Sports_Sedan cars'***/
/***with separate table for Sports and Sedan ***/
Title 'Sports/Sedan cars';
proc print data=sashelp.cars noobs;
where Type in('Sports','Sedan');
Run;
ods excel close;
proc sort data=sashelp.class out=class;
by sex;
run;
options nobyline;
ods excel file= "c:\temp\ReportX.xlsx"
options( sheet_name= '#byval1');
/***Each Sex has a different sheet**/
proc print data=class;
by sex;
run;
ods excel options(sheet_name='Acura Cars');
/***Export to another sheet called 'Acura_Cars'***/
Title 'Acura Cars';
proc print data=sashelp.cars noobs;
where make='Acura';
Run;
ods excel options(sheet_name='Sports/Sedan Cars');
/***Export to another sheet called 'Sports_Sedan cars'***/
/***with separate table for Sports and Sedan ***/
Title 'Sports/Sedan cars';
proc print data=sashelp.cars noobs;
where Type in('Sports','Sedan');
Run;
ods excel close;
Or try PROC EXPORT .
Thanks,
You wrote :
I want to have 2 seprate tables in sheet Sports_Sedan_cars.
In the code that you wrote ,where do you ask to create 2 seprate tables (in same sheet Sports_Sedan_cars)?
ods excel options(sheet_name='Sports/Sedan Cars');
/***Export to another sheet called 'Sports_Sedan cars'***/
/***with separate table for Sports and Sedan ***/
Title 'Sports/Sedan cars';
proc print data=sashelp.cars noobs;
where Type in('Sports','Sedan');
Run;
ods excel close;
OK. If I understand what you mean .
proc sort data=sashelp.class out=class;
by sex;
run;
options nobyline;
ods excel file= "c:\temp\ReportX.xlsx"
options( sheet_name= '#byval1');
/***Each Sex has a different sheet**/
proc print data=class;
by sex;
run;
ods excel options(sheet_name='Acura Cars');
/***Export to another sheet called 'Acura_Cars'***/
Title 'Acura Cars';
proc print data=sashelp.cars noobs;
where make='Acura';
Run;
ods excel options(sheet_name='Sports/Sedan Cars' sheet_interval='none');
/***Export to another sheet called 'Sports_Sedan cars'***/
/***with separate table for Sports and Sedan ***/
Title 'Sports/Sedan cars';
proc print data=sashelp.cars noobs;
where Type in('Sports');
Run;
proc print data=sashelp.cars noobs;
where Type in('Sedan');
Run;
ods excel close;
OK. Just add one more PROC SORT.
proc sort data=sashelp.cars(where=(Type in('Sports' 'Sedan'))) out=temp;by type;run;
ods excel options(sheet_name='Sports/Sedan Cars' sheet_interval='none');
/***Export to another sheet called 'Sports_Sedan cars'***/
/***with separate table for Sports and Sedan ***/
Title 'Sports/Sedan cars';
proc print data=temp noobs;
by type ;
Run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.