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

This is my code so far

proc report data=report nowindows headline headskip SPANROWS split='|' spacing=4 
		style(header)={ just=center asis=on} 
		style(column)={asis=on} 
		style(report)={width=9 in};
		by pageno;

column pageno Varlab PACT_MNGT PACT_SEEKDR PACT_RESP PACT_OTPTS PACT_MED PACT_VIT PACT_INFRMDR PACT_ADHERE PACT_OPTIONS PACT_FACTR PACT_RESRCH;

  define pageno     / order order=data noprint;
  define Varlab      /order display "Item" group order = data style(header)=[just=left fontweight=bold  asis=on] style(column)=[just=left fontweight=bold asis=on cellwidth=0.5in];
  define PACT_MNGT       /order display order = data style(header)=[just=left fontweight=bold  asis=on] style(column)=[just=left asis=on cellwidth=.25in];
  define PACT_SEEKDR       /order display order = data style(header)=[just=left fontweight=bold  asis=on] style(column)=[just=left asis=on cellwidth=.25in];
  define PACT_RESP       /order display order = data style(header)=[just=left fontweight=bold  asis=on] style(column)=[just=left asis=on cellwidth=.25in];
  define PACT_OTPTS       /order display order = data style(header)=[just=left fontweight=bold  asis=on] style(column)=[just=left asis=on cellwidth=.25in];
  define PACT_MED       /order display order = data style(header)=[just=left fontweight=bold  asis=on] style(column)=[just=left asis=on cellwidth=.25in];
  define PACT_VIT       /order display order = data style(header)=[just=left fontweight=bold  asis=on] style(column)=[just=left asis=on cellwidth=.25in];
  define PACT_INFRMDR       /order display order = data style(header)=[just=left fontweight=bold  asis=on] style(column)=[just=left asis=on cellwidth=.25in];
  define PACT_ADHERE       /order display order = data style(header)=[just=left fontweight=bold  asis=on] style(column)=[just=left asis=on cellwidth=.25in];
  define PACT_OPTIONS       /order display order = data style(header)=[just=left fontweight=bold  asis=on] style(column)=[just=left asis=on cellwidth=.25in];
  define PACT_FACTR       /order display order = data style(header)=[just=left fontweight=bold  asis=on] style(column)=[just=left asis=on cellwidth=.25in];
  define PACT_RESRCH       /order display order = data style(header)=[just=left fontweight=bold  asis=on] style(column)=[just=left asis=on cellwidth=.25in];

  	compute PACT_MNGT;
		if PACT_MNGT GE 0.80 AND PACT_MNGT LT 1 then call define(_col_,"style","style={background=red}");
		else if PACT_MNGT LE 0.40 then call define(_col_,"style","style={background=yellow}");
	endcomp;
	compute PACT_SEEKDR;
		if PACT_SEEKDR GE 0.80 AND PACT_SEEKDR LT 1 then call define(_col_,"style","style={background=red}");
		else if PACT_SEEKDR NE . AND PACT_SEEKDR LE 0.40 then call define(_col_,"style","style={background=yellow}");
	endcomp;
run;

Towards the end, I am applying the same code (in red) to highlight correlations that are GE 0.80 OR LE 0.40 for all 11 item variables. Is there an easy way to do this without copying and pasting each comp/endcomp block and changing the variable within each block in proc report?  Basically I am asking, is there a way I can write one comp/endcomp block and apply the same conditional formatting for all 11 PACT variables?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

When you have multiple variables that will use the same range, or a few ranges to set properties like background color you can do that with a FORMAT and the Style for the variable.

Here is an example with a set you should have installed as a demonstration.

proc format;
value colorcode 
low - 70 = 'yellow'
70<-high = 'red';
run;

proc report data=sashelp.class;
  columns name height weight;
  define name/ display;
  define height/display style=[background=colorcode.];  
  define weight/display style=[background=colorcode.];
run;

 The format for the example you show would look like. Colorcode is the name of the format.

proc format;
value colorcode 
low - .40 = 'yellow'
.80 -< 1 = 'red';
run;

You can have multiple formats and use for the range you need for different variables. Do not name the format ending in digits as formats treat digit as related to numbers of characters displayed.

The "low" is a special meaning of small values but not equal to missing. The < is used for comparisons, - indicates a range of values (could be a comma delimited list of specific values). so 3 <- 5 is like the (3,5] interval with the 3 not included but 5 is, 3 -<5 is like [3 , 5) where 3 is included and 5 is not and 3<-<5 is like (3,5) where the endpoints are not included (if you remember the right algebra or calculus class).

 

 

View solution in original post

1 REPLY 1
ballardw
Super User

When you have multiple variables that will use the same range, or a few ranges to set properties like background color you can do that with a FORMAT and the Style for the variable.

Here is an example with a set you should have installed as a demonstration.

proc format;
value colorcode 
low - 70 = 'yellow'
70<-high = 'red';
run;

proc report data=sashelp.class;
  columns name height weight;
  define name/ display;
  define height/display style=[background=colorcode.];  
  define weight/display style=[background=colorcode.];
run;

 The format for the example you show would look like. Colorcode is the name of the format.

proc format;
value colorcode 
low - .40 = 'yellow'
.80 -< 1 = 'red';
run;

You can have multiple formats and use for the range you need for different variables. Do not name the format ending in digits as formats treat digit as related to numbers of characters displayed.

The "low" is a special meaning of small values but not equal to missing. The < is used for comparisons, - indicates a range of values (could be a comma delimited list of specific values). so 3 <- 5 is like the (3,5] interval with the 3 not included but 5 is, 3 -<5 is like [3 , 5) where 3 is included and 5 is not and 3<-<5 is like (3,5) where the endpoints are not included (if you remember the right algebra or calculus class).

 

 

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
  • 1 reply
  • 684 views
  • 0 likes
  • 2 in conversation