Hello,
I would like to alternate 2 colors in proc report for each new value in a column (row).
row
20
20
20
22
23
23
24
so all rows with value=20 will have lightgray color
row with value=22 will have lightgreen color
all rows with value=23 will have lightgrey color
and so on.
The values are not fixed. So I guess i have to first create a variable as compute variable (flag).
Can you please help ?
ods listing close;
proc report data=dupl nowd;
compute flag;
if flag=0 then call define(_row_, "style", "style=[background=lightgray]");
if flag=1 then call define(_row_, "style", "style=[background=lightgreen]");
endcomp;
run;
ods excel close;
Hi @nesslee
Here is a way to do this -> the idea is to compute a flag that changes each time there is a new value.
Depending on whether the flag is an odd or even number (cf. mod() function), the color changes.
Best,
data dupl;
input value;
datalines;
20
20
20
22
23
23
24
;
run;
data dupl2;
set dupl;
by value notsorted;
if first.flag then flag=0;
_lag = lag(value);
if _lag ne value then flag+1;
run;
proc report data=dupl2 nowd;
column value flag;
define value / display;
define flag / display noprint ;
compute flag;
if mod(flag,2)=1 then call define(_row_, "style", "style=[background=lightgray]");
else call define(_row_, "style", "style=[background=lightgreen]");
endcomp;
run;
Hi @nesslee
Here is a way to do this -> the idea is to compute a flag that changes each time there is a new value.
Depending on whether the flag is an odd or even number (cf. mod() function), the color changes.
Best,
data dupl;
input value;
datalines;
20
20
20
22
23
23
24
;
run;
data dupl2;
set dupl;
by value notsorted;
if first.flag then flag=0;
_lag = lag(value);
if _lag ne value then flag+1;
run;
proc report data=dupl2 nowd;
column value flag;
define value / display;
define flag / display noprint ;
compute flag;
if mod(flag,2)=1 then call define(_row_, "style", "style=[background=lightgray]");
else call define(_row_, "style", "style=[background=lightgreen]");
endcomp;
run;
this is great ! thank you so much ! 😄
You're welcome @nesslee 😊
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.