BookmarkSubscribeRSS Feed
Quartz | Level 8



I have the below code:

Problem is- It produces multiple Sheet- Chart, Chart 2.


I want all charts in the same sheet- Chart.


This excel file that i am writing out, already has a tab named- "Data". I don't want to disturb that. I want that as is.


data temp;
infile datalines missover dsd dlm=" ";
input yyyymm pct_change1 pct_change2;
informat yyyymm yymmdd10. pct_change1 pct_change2 percent10.2;
format yyyymm yymmdd10. pct_change1 pct_change2 percent10.2;
2020-05-01 0.74% 0.52%
2020-06-01 0.84% 0.25%
2020-07-01 0.67% 0.62%
2020-08-01 0.52% 0.24%
2020-09-01 0.56% 0.34%
2020-10-01 0.50% 0.45%
2020-11-01 0.37% 0.65%
2020-12-01 1.07% 0.95%
2021-01-01 0.38% 0.25%
2021-02-01 0.34% 0.75%
2021-03-01 0.63% 0.55%
2021-04-01 0.80% 0.68%
2021-05-01 0.71% 0.28%

%let outfile=/path/on/unix/server/tempreport.xlsx;
ods excel file="&outfile.";
	ods excel options(
	Sheet_name= 'Chart'

%macro charting(variable=,label=,LowerRefLine=,UpperRefLine=); 
proc sgplot data = temp ;
  series x = yyyymm y = &variable. ;
  refline 0 &LowerRefLine.  &UpperRefLine. / axis = y ;
  xaxis label="YearMonth";
  yaxis label="&label.";
%mend charting;
%charting(variable=pct_change1,label=Label For 1);

%charting(variable=pct_change2,label=Label For 2);
ods excel close;

Please advise.


Super User
Unfortunately I don't think ODS EXCEL supports writing to pre-existing Excel files.
Quartz | Level 8

Any other alternative?


Template? GTL?

Super User

Easiest for a one-time is to write to a different Excel file and then copy the sheet to the existing.

Super User

@david27 wrote:

Any other alternative?


Template? GTL?

Depends on what's in that first sheet. If it's just a data table I'd import it and then re-write it out using ODS EXCEL so that the whole thing is one report. 

Or use VBS/VBA to combine Excel files after the fact. 



Secure your spot at the must-attend AI and analytics event of 2024: SAS Innovate 2024! Get ready for a jam-packed agenda featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events.


Register by March 1 to snag the Early Bird rate of just $695! Don't miss out on this exclusive offer. 


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
  • 4 replies
  • 3 in conversation