Hello
I am using proc report and I want to create colors to cells depends on their values related to UCL1 and UCL2 .
I have 2 questions please:
1-Why do I get all cells of X1909,X1908mX1907,X1906 with red color??
Foe example:
For X1909 I should get all cells with no color because none of them is higher then UCL1 value or UCL2 value
2-There is a code that repeat many times.Is there a clever way to write it in short code?
Data rawtbl;
input (X1909 X1908 X1907 X1906 UCL1 UCL2) (:percent.);
format X1909 X1908 X1907 X1906 UCL1 UCL2 percent7.2;
cards;
4% 3% 6% 5.10% 5% 5.20%
3% 2% 2% 4.60% 4.50% 4.90%
5% 5% 5% 5% 7% 8%
;
run;
proc report data=rawtbl nowd;
column X1909 X1908 X1907 X1906 UCL1 UCL2;
define X1909 / display;
define X1908 / display;
define X1907 / display;
define X1906 / display;
define UCL1 / display;
define UCL2 / display;
compute X1909;
if X1909>UCL1 and X1909>UCL2 then call define(_col_,"style","style={background=red}");
else if X1909>UCL1 and X1909<=UCL2 then call define(_col_,"style","style={background=lightred}");
else if X1909<=UCL1 and X1909<=UCL2 then call define(_col_,"style","style={background=pink}");
endcomp;
compute X1908;
if X1908>UCL1 and X1908>UCL2 then call define(_col_,"style","style={background=red}");
else if X1908>UCL1 and X1908<=UCL2 then call define(_col_,"style","style={background=lightred}");
else if X1908<=UCL1 and X1908<=UCL2 then call define(_col_,"style","style={background=pink}");
endcomp;
compute X1907;
if X1907>UCL1 and X1907>UCL2 then call define(_col_,"style","style={background=red}");
else if X1907>UCL1 and X1907<=UCL2 then call define(_col_,"style","style={background=lightred}");
else if X1907<=UCL1 and X1907<=UCL2 then call define(_col_,"style","style={background=pink}");
endcomp;
compute X1906;
if X1906>UCL1 and X1906>UCL2 then call define(_col_,"style","style={background=red}");
else if X1906>UCL1 and X1906<=UCL2 then call define(_col_,"style","style={background=lightred}");
else if X1906<=UCL1 and X1906<=UCL2 then call define(_col_,"style","style={background=pink}");
endcomp;
run;
please not that I have learned from example code
http://support.sas.com/kb/23/353.html
proc report data=sashelp.class nowd;
column name age sex height weight;
define name / display;
define age / display;
define sex / order;
define height / sum;
define weight / sum;
compute age;
if age < 13 then call define(_col_,"style","style={background=red}");
endcomp;
run;
PROC REPORT calculated it from LEFT to RIGHT. Try use the last column UCL2 to compute:
compute UCL2;
if X1909>UCL1 and X1909>UCL2 then call define('X1909',"style","style={background=red}");
else if X1909>UCL1 and X1909<=UCL2 then call define('X1909',"style","style={background=lightred}");
else if X1909<=UCL1 and X1909<=UCL2 then call define('X1909',"style","style={background=pink}");
endcomp;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.