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

Hi,

I try to export data to Excel with color using the following code

 

However, it only export the last sheet.

 

Also, how to add REPLACE option as in proc export?

 

Any help is very much appreciated.

 

HHCFX

 


ods listing close;
ods excel file="C:\Users\_temp\exp.xlsx"   
                    options (sheet_interval = "none" sheet_name = "SHEET1" );

		proc report data=sashelp.class nowd;
		compute name;
		call define (_col_,"style","style={background=lightgray}");
			endcomp;
		run;

ods excel close;


ods listing close;
ods excel file="C:\Users\_temp\exp.xlsx"   
                    options (sheet_interval = "none" sheet_name = "SHEET2" );

		proc report data=sashelp.class nowd;
		compute Weight;
		call define (_col_,"style","style={background=lightgray}");
			endcomp;
		run;

ods excel close;
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Because you have to ODS EXCEL calls it overwrites the previous results with just the final results. If you want the output into two sheets in the same workbook you can simply not close the destination between PROCS.

 

ods listing close;
ods excel file="/folders/myfolders/exp.xlsx"   
                    options (sheet_interval = "proc" sheet_name = "SHEET1" );

        proc report data=sashelp.class nowd;
        compute name;
        call define (_col_,"style","style={background=lightgray}");
            endcomp;
        run;


ods excel  options (sheet_interval = "proc" sheet_name = "SHEET2" );

        proc report data=sashelp.class nowd;
        compute Weight;
        call define (_col_,"style","style={background=lightgray}");
            endcomp;
        run;

ods excel close;

AFAIK there is no REPLACE option specifically, but appears to be the default. You cannot append ODS EXCEL data to an existing Excel file or template.

 


@hhchenfx wrote:

Hi,

I try to export data to Excel with color using the following code

 

However, it only export the last sheet.

 

Also, how to add REPLACE option as in proc export?

 

Any help is very much appreciated.

 

HHCFX

 


ods listing close;
ods excel file="C:\Users\_temp\exp.xlsx"   
                    options (sheet_interval = "none" sheet_name = "SHEET1" );

		proc report data=sashelp.class nowd;
		compute name;
		call define (_col_,"style","style={background=lightgray}");
			endcomp;
		run;

ods excel close;


ods listing close;
ods excel file="C:\Users\_temp\exp.xlsx"   
                    options (sheet_interval = "none" sheet_name = "SHEET2" );

		proc report data=sashelp.class nowd;
		compute Weight;
		call define (_col_,"style","style={background=lightgray}");
			endcomp;
		run;

ods excel close;

 

View solution in original post

2 REPLIES 2
Reeza
Super User

Because you have to ODS EXCEL calls it overwrites the previous results with just the final results. If you want the output into two sheets in the same workbook you can simply not close the destination between PROCS.

 

ods listing close;
ods excel file="/folders/myfolders/exp.xlsx"   
                    options (sheet_interval = "proc" sheet_name = "SHEET1" );

        proc report data=sashelp.class nowd;
        compute name;
        call define (_col_,"style","style={background=lightgray}");
            endcomp;
        run;


ods excel  options (sheet_interval = "proc" sheet_name = "SHEET2" );

        proc report data=sashelp.class nowd;
        compute Weight;
        call define (_col_,"style","style={background=lightgray}");
            endcomp;
        run;

ods excel close;

AFAIK there is no REPLACE option specifically, but appears to be the default. You cannot append ODS EXCEL data to an existing Excel file or template.

 


@hhchenfx wrote:

Hi,

I try to export data to Excel with color using the following code

 

However, it only export the last sheet.

 

Also, how to add REPLACE option as in proc export?

 

Any help is very much appreciated.

 

HHCFX

 


ods listing close;
ods excel file="C:\Users\_temp\exp.xlsx"   
                    options (sheet_interval = "none" sheet_name = "SHEET1" );

		proc report data=sashelp.class nowd;
		compute name;
		call define (_col_,"style","style={background=lightgray}");
			endcomp;
		run;

ods excel close;


ods listing close;
ods excel file="C:\Users\_temp\exp.xlsx"   
                    options (sheet_interval = "none" sheet_name = "SHEET2" );

		proc report data=sashelp.class nowd;
		compute Weight;
		call define (_col_,"style","style={background=lightgray}");
			endcomp;
		run;

ods excel close;

 

hhchenfx
Barite | Level 11

Thank you,

HHC

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 3378 views
  • 0 likes
  • 2 in conversation