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?
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):
:
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
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_
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 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: