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

Dear community,

 

I have created a fake by variable in order to be able to name sheets using #byval1 in ods excel output while using multiple proc report calls.

ods excel file="foo.xlsx" options(sheet_name="#byval1");

proc report data=foo;
by dsname;
quit;

proc report data=bar;
by dsname;
quit;

ods excel close;

While it worked in terms of giving the sheets human-readable names, I now have dsname=foo present as subtitle in the sheets. As each dataset reported on has just one value of the dsname variable, this carries no information and I would like to remove it. Is there a parameter to proc report which could accomplish the job?

Alternatively, is there a way to dynamically name the sheets of ods excel other than using #byval? Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@js5 wrote:
That is exactly what I needed, thanks!
Is there a less crude way of naming the sheets dynamically when using multiple proc report calls? Adding a fake variable containing the dataset name and using by with single value seems a bit crude.

It depends on what you mean by "dynamically". And to some extent the exact nature of your proc report calls.

 

If your Proc Report code is not being generated dynamically then it may just be easier to add an

 

ods excel options(sheet_name="dataset");

before each proc report changing the text of "dataset" as desired. I typically do this because SAS dataset names aren't necessarily "pretty". So I could use sheet_name="Child Age" instead of sheet_name="childage".

 

If you have some macro that generates the proc report code from a parameter list that includes a dataset name then you could dynamically add that ODS Excel option before the proc report code as part of the macro such as:

 

%macro genericreport(libname=work,dsname=_last_);
ods excel options(sheet_name="&dsname.");
proc report data=&libname..&dsname.;
run;
%mend;


ods excel file="foo.xlsx" ;

%genericreport(dsname=foo);
%genericreport(dsname=bar);

ods excel close;

If you have any more options to the Proc Report code though it would likely be easier just to add the separate ODS EXcel options as needed since you are already typing out the proc report. The extremely lazy could create very short macro to do just that line with the desired text.

 

View solution in original post

4 REPLIES 4
jimhorne
Obsidian | Level 7
Have you tried OPTIONS NOBYLINE?
js5
Pyrite | Level 9 js5
Pyrite | Level 9
That is exactly what I needed, thanks!
Is there a less crude way of naming the sheets dynamically when using multiple proc report calls? Adding a fake variable containing the dataset name and using by with single value seems a bit crude.
ballardw
Super User

@js5 wrote:
That is exactly what I needed, thanks!
Is there a less crude way of naming the sheets dynamically when using multiple proc report calls? Adding a fake variable containing the dataset name and using by with single value seems a bit crude.

It depends on what you mean by "dynamically". And to some extent the exact nature of your proc report calls.

 

If your Proc Report code is not being generated dynamically then it may just be easier to add an

 

ods excel options(sheet_name="dataset");

before each proc report changing the text of "dataset" as desired. I typically do this because SAS dataset names aren't necessarily "pretty". So I could use sheet_name="Child Age" instead of sheet_name="childage".

 

If you have some macro that generates the proc report code from a parameter list that includes a dataset name then you could dynamically add that ODS Excel option before the proc report code as part of the macro such as:

 

%macro genericreport(libname=work,dsname=_last_);
ods excel options(sheet_name="&dsname.");
proc report data=&libname..&dsname.;
run;
%mend;


ods excel file="foo.xlsx" ;

%genericreport(dsname=foo);
%genericreport(dsname=bar);

ods excel close;

If you have any more options to the Proc Report code though it would likely be easier just to add the separate ODS EXcel options as needed since you are already typing out the proc report. The extremely lazy could create very short macro to do just that line with the desired text.

 

js5
Pyrite | Level 9 js5
Pyrite | Level 9

Thanks, this did the trick! I did not know that you can call ods excel multiple times in addition to ods excel file... and ods excel close.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 1252 views
  • 2 likes
  • 3 in conversation