Hi,
I have a dataset with 5 fields.
study, site, subject, total_q, closed_q
I would like to color the closed_q field based on closed_q/total_q.
I tried this, but it is not works.
proc report data = sr.drs nowd;
columns study site subject total_q closed_q ;
define study/group ;
define site/group ;
define total_q / analysis style(header)=[background=olive];
define closed_q / analysis style(header)=[background=olive];
compute closed_q;
if round((closed_q/total_q)*100,0.01)<50 then call define (_col_,"style","STYLE=[BACKGROUND=RED]");
else if round((closed_q/total_q)*100,0.01)>=50 and round((closed_q/total_q)*100,0.01)<75 then call define (_col_,"style","STYLE=[BACKGROUND=ROSE]");
else if round((closed_q/total_q)*100,0.01)>=75 and round((closed_q/total_q)*100,0.01)<85 then call define (_col_,"style","STYLE=[BACKGROUND=ORANGE]");
else if round((closed_q/total_q)*100,0.01)>=85 and round((closed_q/total_q)*100,0.01)<95 then call define (_col_,"style","STYLE=[BACKGROUND=YELLOW]");
else if round((closed_q/total_q)*100,0.01)>=95 then call define (_col_,"style","STYLE=[BACKGROUND=GREEN]");
endcomp;
break after site / skip summarize style=[background=CXF2F2F2 font_weight=bold];
break after study / skip summarize style=[background=CXFFFFCC font_weight=bold];
run;I tried another solution, I added one more field (pq) to the dataset with the value of closed_q/total_q:
proc sql;
update sr.drs set pq=round((closed_q/total_q)*100,0.01);
quit;
proc report data = sr.drs nowd;
columns study site subject pq total_q closed_q ;
define study/group ;
define site/group ;
define pq / analysis mean noprint;
define total_q / analysis style(header)=[background=olive];
define closed_q / analysis style(header)=[background=olive];
compute closed_q;
if pq<50 then call define (_col_,"style","STYLE=[BACKGROUND=RED]");
else if pq>=50 and pq<75 then call define (_col_,"style","STYLE=[BACKGROUND=ROSE]");
else if pq>=75 and pq<85 then call define (_col_,"style","STYLE=[BACKGROUND=ORANGE]");
else if pq>=85 and pq<95 then call define (_col_,"style","STYLE=[BACKGROUND=YELLOW]");
else if pq>=95 then call define (_col_,"style","STYLE=[BACKGROUND=GREEN]");
endcomp;
break after site / skip summarize style=[background=CXF2F2F2 font_weight=bold];
break after study / skip summarize style=[background=CXFFFFCC font_weight=bold];
run;I have the same issue, closed_q column is always red.
Could you please help me what is wrong here?
Thank you in advance!
Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.
Explore Now →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.