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

I have a PROC REPORT table in which I want to bold cell based on comparison with other cells. Here is the code and current output.

Code: 

proc report data=gender_t2c nowd split="*"
		style(report)=[frame=hsides rules=none]
		style(header)=[background=white color=&rgreen. borderbottomcolor=black]
		style(lines)=[background=white];
	column injsite boys_soccer girls_soccer estimate lowercl uppercl ci;
	define injsite / 'Body Site' group order = data;
	define boys_soccer / "Boys' Soccer" analysis pctsum format=pct. style(column)=[cellwidth=1.5in just=c];
	define girls_soccer / "Girls' Soccer" analysis pctsum format=pct. style(column)=[cellwidth=1.5in just=c];
	define estimate / '' display noprint;
	define lowercl / '' display noprint;
	define uppercl / '' display noprint;
	define ci / "IPR (95% CI)" display style(column)=[cellwidth=1.5in just=c];

	rbreak after / summarize style(summary)={font_weight=bold};
	compute after;
		injsite = 'Total';
	endcomp;
run;

Output:

plot.png

There are two comparisons/boldings that I want to perform:

  1. Bold the cell value between Boys' Soccer and Girls' Soccer that is the largest
  2. Bold any IPRs where 1 is not in the interval given

I am exploring how to do this with COMPUTE and CALL DEFINE commands, but cannot quite make it work.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Since font weight isn't always obvious enough I colored the cell yellow or pink:

 

proc report data=test nowd;
	column cat a b;
	define cat / '' group order = data;
	define a / 'a' analysis pctsum format=percent8.1;
	define b / 'b' analysis pctsum format=percent8.1;

	compute b;
	     if b.pctsum > a.pctsum then call define(_col_,'style','style={font_weight=bold background=yellow}');
             if a.pctsum > b.pctsum then call define(2,'style','style={font_weight=bold background=pink}');
	endcomp;

	rbreak after / summarize;
run;

@Cynthia_sas stated that you need to reference the calculated statistic for the comparison. Note that the 2 in the second statement is the column number of the A statistic.

 

View solution in original post

5 REPLIES 5
ballardw
Super User

Provide example data in the form of a data step.

 

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the </> icon or attached as text to show exactly what you have and that we can test code against.

Cynthia_sas
SAS Super FREQ

Hi:
What code have you tried? You said you can't make it work. Nobody else can make it work without making up some fake data including your NOPRINT variables which do not seem to be used. PROC REPORT has 2 rules that you need to consider before you try to apply changes with CALL DEFINE:
1) you have to refer to analysis items by their "internal name" -- which is variable.statistic
2) PROC REPORT has a "left to right" rule -- each item is placed on the report row, one item at a time. So for example, with this column statement:
column cat a b tot;
at the point in time that PROC REPORT is writing CAT on the report row, it has no visibility of the values of A, B or TOT. When Proc Report places A on the report row, then it has visibility of only the value for A and CAT (there is no visibility for B or TOT yet). So working from left to right you can't do a comparison between A and B (for example) until both A and B have been placed on the report row. This means a comparison will fail if placed in a COMPUTE block for A, but will work when placed in the COMPUTE block for B or TOT (which are to the right of A on the report row).

Consider this example with fake data, since you did not show all your code or provide any data:

Cynthia_sas_0-1597847605203.png

 

  Note the use of A.SUM and B.SUM in the code because both A and B are analysis items and the statistic requested is SUM. If I had requested the MEAN, then the reference would have been A.MEAN and B.MEAN, etc.
Hope this helps,
Cynthia

tburus
Obsidian | Level 7

I have crafted a test set to explain what I mean (the NOPRINT columns are something else I'm working with that's already settled).

data test;
input cat $ a b;
datalines;
A 4 5 
B 2 7
C 8 4
D 1 9
;
run;

proc report data=test nowd;
	column cat a b;
	define cat / '' group order = data;
	define a / 'a' analysis pctsum format=percent8.1;
	define b / 'b' analysis pctsum format=percent8.1;

	compute b;
		if b > a then call define(_col_,'style','style={font_weight=bold}');
	endcomp;

	rbreak after / summarize;
run;

The COMPUTE block is where I need help. I want it to compare the PCTSUM in each row for a and b. If the PCTSUM of b is larger, I want to bold b in that row; if the PCTSUM of a is larger, I want to bold a in that row. (It's highly unlikely that they will be equal in my application, but I guess we could make the first condition greater than or equal to.) Thanks.

ballardw
Super User

Since font weight isn't always obvious enough I colored the cell yellow or pink:

 

proc report data=test nowd;
	column cat a b;
	define cat / '' group order = data;
	define a / 'a' analysis pctsum format=percent8.1;
	define b / 'b' analysis pctsum format=percent8.1;

	compute b;
	     if b.pctsum > a.pctsum then call define(_col_,'style','style={font_weight=bold background=yellow}');
             if a.pctsum > b.pctsum then call define(2,'style','style={font_weight=bold background=pink}');
	endcomp;

	rbreak after / summarize;
run;

@Cynthia_sas stated that you need to reference the calculated statistic for the comparison. Note that the 2 in the second statement is the column number of the A statistic.

 

Cynthia_sas
SAS Super FREQ

Hi:

  As I explained in my posting, you MUST use the variable.statistic reference in a COMPUTE block for your reference to any variables. Here are some examples:

A.SUM

B.SUM

A.MEAN

Otherwise, PROC REPORT will generate an error. So if A is an analysis variable and if the statistic for A is PCTSUM -- then the compound name for referencing purpose would need to be A.PCTSUM -- that is the rule I mentioned in my post. And there are other ways you could reference the column, such as indirect reference or macro variable or some other resolved method. But I prefer to show the compound name because that will always work, even if another item gets inserted into the row and the number could change. For example, if the column statement was 

column CAT GRP A B, then the number for A would change. but the reference of A.PCTSUM would NOT change, even if the position changed. (As long as the statistic was the same.)

 

Cynthia

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 5 replies
  • 2419 views
  • 0 likes
  • 3 in conversation