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
SAS Super FREQ
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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 655 views
  • 0 likes
  • 3 in conversation