BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi,

I like to use different format depends on the value of the row variable (TESTCODE) in Proc Tabulate.

For example, if TESTCODE = 'ANA', then it should use {STYLE={BACKGROUND=ANA_COL.}}. if TESTCODE = 'DNA', then it should use {STYLE={BACKGROUND=DNA_COL.}}.

Any idea how I can do this??
See the attached code below.

Thank you.
James

-----------------------------------------

PROC FORMAT;
value ANA_COL 0-23 = 'GREEN' 23<-HIGH = 'RED' . = 'WHITE' OTHER = 'BLACK';
value DNAR_COL 0-<7 = 'GREEN' 7-HIGH = 'RED' . = 'WHITE' OTHER = 'BLACK';
value DNA_COL 0-20 = 'GREEN' 20<-HIGH = 'RED' . = 'WHITE' OTHER = 'BLACK';
value ENA_COL 0-<8 = 'GREEN' 8-10 = 'BLUE' 10<-HIGH = 'RED' . = 'WHITE' OTHER = 'BLACK';
RUN;

PROC TABULATE DATA = IN MISSING;
TITLE;
CLASS SUBJID LBDT TESTCODE VISIT_ID;
VAR LBORRESN;
TABLE SUBJID, TESTCODE, LBDT*LBORRESN*{STYLE={BACKGROUND=ANA_COL.}};
RUN;
3 REPLIES 3
David_SAS
SAS Employee
What you're wanting to do is not possible. You can't vary formats based on data values.

-- David Kelley, SAS
deleted_user
Not applicable
Thanks.

Can you think of any other way to do this??

James
Cynthia_sas
Diamond | Level 26
David is correct that this is not something that TABULATE does. You might approximate what you want to do with PROC REPORT. In this program, differing formats are applied based on the "row" variable for DIVISION using a CALL DEFINE in a COMPUTE block:[pre]

proc format;
value CON 0-< 50000 = 'yellow'
50000-high = 'pink';
value EDU 0-< 70000 = 'beige'
70000-high = 'cyan';
run;

ods html file='c:\temp\rep_hilite.html'
style=sasweb;

proc report data=sashelp.prdsale nowd;
column country division prodtype,actual;
define country /group noprint;
define division/group;
define prodtype / across;
define actual / sum 'Sales';
compute actual;
if division = 'CONSUMER' then do;
call define('_C3_','STYLE','style={background=CON.}');
call define('_C4_','STYLE','style={background=CON.}');
end;
if division = 'EDUCATION' then do;
call define('_C3_','STYLE','style={background=EDU.}');
call define('_C4_','STYLE','style={background=EDU.}');
end;
endcomp;
by country;
run;
ods html close;
[/pre]
Although there is a bit of brute force programming in that the format is not automatically set, but has to be done inside the CALL DEFINE, this may provide you something close to what you want.

The solution could be adapted to use macro variables, macro do loops or arrays if you have a lot of across variables. I show the "hard-coded" method because I only have 2 across variables.
cynthia

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1087 views
  • 0 likes
  • 3 in conversation