I'm using a BY statement in PROC REPORT and report is correctly exported to excel with separate work sheet for each group in the BY variable.
I like to display the corresponding group variable value as a Column Label in each work sheet. Can you suggest a solution?
proc report data=ABC
BY GRP_VARIABLE;
COLUMN C1 C2
define C1 / center display 'First Column';
define C2 / center display '<Group Variable Value>';
I' m trying get the group variable value and display that as column label or as part of the title on each work sheet. Please advice. Thank you.
Hi:
This type of output is possible in Excel using the ODS EXCEL destination, as shown below:
(only showing 2 of the sheets for age 13 and age 14)
In order to accomplish this, several features needed to be turned on:
Using the BY statement enabled the use of #byval1 for the sheet names and also enabled a separate sheet to start for every BY group value. Note how, with embedded_titles='yes', the value of the title, including the #byval1 value appears on each sheet.
Although you can't use #byval1 as a column header value, if you also have the BY variable (in this case, AGE) as an ORDER variable on the report, you can do a COMPUTE BEFORE _PAGE_ block in order to write a header line that spans the whole table for that age. Note how the TITLE string is sitting outside of the table boundaries, but the COMPUTE block LINE output is styled as a header row above the table, but inside the table boundaries.
Hope this helps explain how you could get close to what you want.
Cynthia
I don't think that changing the label of a variable is possible during runtime at all. In a title-statement, you could use #byvar (as documented in https://documentation.sas.com/?docsetId=lestmtsref&docsetTarget=p10gcmrmf83iaxn1ilrx4pra969n.htm&doc...) to display the value of the by-variable, unfortunately this doesn't work within define-statement. Maybe this could be achieved by using a compute-block.
@DLROW wrote:
I'm using a BY statement in PROC REPORT and report is correctly exported to excel with separate work sheet for each group in the BY variable.
I like to display the corresponding group variable value as a Column Label in each work sheet. Can you suggest a solution?
proc report data=ABC
BY GRP_VARIABLE;
COLUMN C1 C2
define C1 / center display 'First Column';
define C2 / center display '<Group Variable Value>';I' m trying get the group variable value and display that as column label or as part of the title on each work sheet. Please advice. Thank you.
Instead of BY grp_variable, add grp_variable to the COLUMN statement and the define it as a GROUP variable. Using a COMPUTE AFTER statement, you can send the output to a new page/new worksheet in Excel.
Hi:
This type of output is possible in Excel using the ODS EXCEL destination, as shown below:
(only showing 2 of the sheets for age 13 and age 14)
In order to accomplish this, several features needed to be turned on:
Using the BY statement enabled the use of #byval1 for the sheet names and also enabled a separate sheet to start for every BY group value. Note how, with embedded_titles='yes', the value of the title, including the #byval1 value appears on each sheet.
Although you can't use #byval1 as a column header value, if you also have the BY variable (in this case, AGE) as an ORDER variable on the report, you can do a COMPUTE BEFORE _PAGE_ block in order to write a header line that spans the whole table for that age. Note how the TITLE string is sitting outside of the table boundaries, but the COMPUTE block LINE output is styled as a header row above the table, but inside the table boundaries.
Hope this helps explain how you could get close to what you want.
Cynthia
Thank you all. I was able to get the 'BY variable' in the title.
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.