BookmarkSubscribeRSS Feed
PaigeMiller
Diamond | Level 26

I can perform a PROC REPORT and highlight certain rows with whatever color I choose, for example:

 

ods html;
proc report data=sashelp.class nowindows;
	columns age sex,height;
	define age/group;
	define sex/display across;
	define height/mean;
	compute height;
		if age=15 then call define('_c2_','style','style={background=lightmoderatered}');
		if age=15 then call define('_c3_','style','style={background=lightmoderatered}');
	endcompute;
run;
ods html close;

But what I really want is to have different formats in different rows, is this possible in PROC REPORT (or anywhere)? If so, how?

--
Paige Miller
2 REPLIES 2
Cynthia_sas
SAS Super FREQ

Hi, just as you can use "style" as the second argument for call define, you can use "format" for the second argument. There have been previous postings on the topic and it is shown in the PROC REPORT documentation.

And, _ROW_ is a valid choice for argument 1 (_COL_ and _ROW_ do not have to be quoted as argument 1).

Argument 3 is the format, as an example:
call define(_ROW_,"format","dollar14.2");

Hope this helps, Here's an example using SASHELP.CLASS:

ods html file='c:\temp\hilite.html';
proc report data=sashelp.class nowindows;
	columns age sex,height;
	define age/group;
	define sex/ across;
	define height/mean f=5.1;
	compute height;
		if age=15 then do;
           call define(_row_,'style','style={background=lightmoderatered}');
		   call define('_c2_','format','9.4');
		   call define('_c3_','format','9.4');
		end;
	endcomp;
run;
ods html close;

(the DISPLAY ACROSS that you had for the SEX variable was unnecessary. DISPLAY is not the correct usage, ACROSS is the correct usage.)

 

The results are (note how the AGE cell is also red):

call_define_format.png:

 

  Note that in the code, I could use the color with _ROW_, but for the format I had to use the absolute column numbers. If you changed the COMPUTE block to this:

	compute height;
		if age=15 then do;
           call define(_row_,'style','style={background=lightmoderatered}');
		   call define(_row_,'format','9.4');
		end;
	endcomp;

The format would not be applied as you want. It is better to be specific anyway with formats, because you might not want that format assigned for  every cell in a row.

 

cynthia

 


cynthia

PaigeMiller
Diamond | Level 26

I get errors if I use _row_, am I doing something wrong?

 

ods html;
proc report data=sashelp.class nowindows;
	columns age sex,height;
	define age/group;
	define sex/display across;
	define height/mean;
	compute height;
		if age=15 then call define(_row_,'format','6.0');
		else call define(_row_,'format','8.2');
	endcompute;
run;
ods html close;

On the other hand, in this example, if I use _c2_ instead of _row_, it works fine.

 

UPDATE — oh I see you are having the same problem with _row_ ... so I'll stick to _c2_ and _c3_

--
Paige Miller

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 2 replies
  • 5099 views
  • 2 likes
  • 2 in conversation