/*OK. Try this code.*/
data WORK.DIAGNOSES;
input diagnosis & $17. _2 _1 group_cat group $20.;
label diagnosis="diagnosis" _2="_2" _1="_1" group_cat="group_cat" group="group";
datalines;
ALL 52 -52 1 Group 1
ALL 2 -2 2 Group 2
AML 10 -20 1 Group 1
AML 6 -10 2 Group 2
Breast Cancer 20 -13 2 Group 2
Breast Cancer 20 -9 1 Group 1
Breast Cancer 8 -3 3 Group 3
Colon Cancer 20 -30 1 Group 1
Lung Cancer 24 -17 1 Group 1
Stomach Cancer 7 -7 4 Group 4
Stomach Cancer 4 -4 3 Group 3
Skin Cancer 1 -1 4 Group 4
Skin Cancer 1 0 3 Group 3
Pancreatic Cancer 2 -2 3 Group 3
Prostate Cancer 2 0 5 Group 5
;
proc sort data=DIAGNOSES out=have;
by diagnosis group;
run;
data have2;
set have;
by diagnosis;
if first.diagnosis then call missing(cum1,cum2);
mean1=-sum(cum1,-_1/2);
mean2=sum(cum2,_2/2);
cum1+(-_1);
cum2+_2;
drop cum1 cum2;
run;
proc sql;
create table have3 as
select *,sum(sum(_2,-_1)) as total
from have2
group by diagnosis
order by total desc,diagnosis;
quit;
proc format;
picture positive
low -< 0 = "0000"
0 <- high = "0000";
run;
ods path work.tmp(update) sasuser.templat(update) sashelp.tmplmst(read);
proc template;
define style styles.garamond;
parent=styles.htmlblue; /* Or your favorite style */
style graphfonts from graphfonts /
'GraphDataFont' = ("Arial, <MTsans-serif>",7pt)
'GraphUnicodeFont' = ("<MTsans-serif-unicode>",9pt)
'GraphValueFont' = ("Arial, <MTsans-serif>",9pt)
'GraphLabel2Font' = ("Arial, <MTsans-serif>",10pt)
'GraphLabelFont' = ("Arial, <MTsans-serif>",10pt)
'GraphFootnoteFont' = ("Arial, <MTsans-serif>",10pt)
'GraphTitleFont' = ("Arial, <MTsans-serif>",11pt,bold)
'GraphTitle1Font' = ("Arial, <MTsans-serif>",14pt)
'GraphAnnoFont' = ("Arial, <MTsans-serif>",10pt);
end;
run;
ods _all_ close;
ods listing style=garamond gpath='c:\temp\';
ods graphics /outputfmt=png reset=index imagename='want';
proc sgplot data = have3 noborder nowall ;
styleattrs datacontrastcolors=(black black white white white) datacolors=(VLIGB red blue black maroon);
format _1 positive.;
format _2 positive.;
hbarparm category=diagnosis response = _1/ group = group groupdisplay = stack barwidth=0.9 grouporder=ascending nooutline name="c1" nozerobars;
hbarparm category=diagnosis response = _2/ group = group groupdisplay = stack barwidth=0.9 grouporder=ascending nooutline nozerobars ;
text x=mean1 y=diagnosis text=_1 /contributeoffsets=none strip group = group textattrs=(size = 9 weight = bold);
text x=mean2 y=diagnosis text=_2 /contributeoffsets=none strip group = group textattrs=(size = 9 weight = bold);
xaxis labelattrs = (weight = bold) display=(noticks) label = "Patients (%)" values = (-80 to 80 by 20);
yaxis display = (noline nolabel noticks) discreteorder = data valueattrs = (weight=bold color=black size=10) label="Patients";
keylegend "c1"/ across = 10 noborder title = '' valueattrs=(size=11) sortorder=ascending;
inset "Insert" / position = bottomleft textattrs = (color = black size = 10 weight = bold style = normal);
inset "Insert" / position = bottomright textattrs = (color = black size = 10 weight = bold style = normal);
run;
1. Is there a way to order the bars (can be based on the right or left side) by total bar length? Initially, I ordered my data in excel but this changed the arrangement.
2. Can you rerun the code with a more unique font? Maybe "brush". For me it seems as though the font is still not changing. I changed the "Arial" in your code to brush and the font didn't change.
3. In my dataset, several rows had zeros for the "_1" variable so I removed them from the file, leaving blank cells. One of the bars now says "dot" instead of the zero. Do you know how I can remove this? Below is a screenshot.
... View more