The SAS Output Delivery System and reporting techniques

PROC REPORT — different formats for different rows?

Reply
Respected Advisor
Posts: 2,647

PROC REPORT — different formats for different rows?

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
SAS Super FREQ
Posts: 9,251

Re: PROC REPORT — different formats for different rows?

[ Edited ]
Posted in reply to PaigeMiller

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

Respected Advisor
Posts: 2,647

Re: PROC REPORT — different formats for different rows?

[ Edited ]
Posted in reply to Cynthia_sas

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
Ask a Question
Discussion stats
  • 2 replies
  • 157 views
  • 0 likes
  • 2 in conversation