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

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi:

  This type of output is possible in Excel using the ODS EXCEL destination, as shown below:

Cynthia_sas_0-1586026506543.png

(only showing 2 of the sheets for age 13 and age 14)

  In order to accomplish this, several features needed to be turned on:

Cynthia_sas_1-1586026549181.png

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

View solution in original post

4 REPLIES 4
andreas_lds
Jade | Level 19

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.

PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
Cynthia_sas
SAS Super FREQ

Hi:

  This type of output is possible in Excel using the ODS EXCEL destination, as shown below:

Cynthia_sas_0-1586026506543.png

(only showing 2 of the sheets for age 13 and age 14)

  In order to accomplish this, several features needed to be turned on:

Cynthia_sas_1-1586026549181.png

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

DLROW
Quartz | Level 8

Thank you all. I was able to get the 'BY variable' in the title. 

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
  • 4 replies
  • 1356 views
  • 1 like
  • 4 in conversation