Hello,
How can I increase the gap before the last confidence interval in forest plot using proc sgplot.
data forest_subgroup;
infile cards truncover expandtabs;
input Id Subgroup : $80. Count Percent : $40. Count_test Percent_test : $40. Mean Low High ci :$40. pvalue $;
indentWt=1;
ObsId=_n_;
datalines;
2 aa 332 6.35(3.45) 111 3.73(3.98) 2.62 1.85 3.39 2.62(1.85,3.39) <0.001
2 1~3 101 5.80(3.43) 36 3.75(4.38) 2.05 0.63 3.47 2.05(0.63,3.47) 0.005
2 4~7 120 6.30(3.69) 37 2.73(3.65) 3.58 2.21 4.95 3.58(2.21,4.95) <0.001
2 8~14 111 6.91(3.12) 38 4.69(3.75) 2.22 0.99 3.44 2.22(0.99,3.44) <0.001
2 <6 78 3.44(2.73) 37 1.31(2.79) 2.13 1.04 3.21 2.13(1.04,3.21) <0.001
2 >6 254 7.25(3.14) 74 4.94(3.95) 2.31 1.32 3.30 2.31(1.32,3.30) <0.001
2 bbb 162 6.32(3.79) 63 3.65(4.43) 2.67 1.50 3.83 2.67(1.50,3.83) <0.001
2 cc 170 6.38(3.09) 48 3.83(3.35) 2.55 1.54 3.56 2.55(1.54,3.56) <0.001
2 dd 298 6.41(3.22) 107 3.78(4.04) 2.64 1.78 3.49 2.64(1.78,3.49) <0.001
2 ee 364 6.23(3.36) 120 3.67(3.91) 2.56 1.78 3.35 2.56(1.78,3.35) <0.001
2 ff 104 5.77(3.39) 37 3.65(4.37) 2.12 0.53 3.71 2.12(0.53,3.71) 0.010
2 gg 135 6.23(3.56) 41 2.91(3.52) 3.32 2.07 4.57 3.32(2.07,4.57) <0.001
1 xxxxxx
2 ALL 125 6.62(3.08) 42 4.44(3.79) 2.19 1.03 3.34 2.19(1.03,3.34) <0.001
;
run;
data forest_subgroup;
set forest_subgroup;
indentWt=1;
ObsId=_n_;
run;
data forest_subgroup_2;
set forest_subgroup nobs=n end=last;
length text $20;
val=mod(_N_-1, 6);
/* if val eq 1 or val eq 2 or val eq 3 then ref=obsid;*/
if mod(obsid,2 )=0 then ref=obsid;
/*--Separate Subgroup headers and obs into separate columns--*/
indentwt=2;
if id=1 then indentWt=0;
output;
if last then do;
call missing (subgroup, count, percent, Count_test ,Percent_test, mean, low, high, ci,
indentwt, val, ref ,pvalue);
obsid=n+1;
xl=1; yl=n+1; text='P'; output;;
xl=4; yl=n+1; text='T'; output;
end;
run;
/*--Define Format with Unicode for the left and right arrows--*/
proc format;;
value $txt
"T" = "test better (*ESC*){Unicode '2192'x}"
"P" = "(*ESC*){Unicode '2190'x} placebo better";
run;
/*--Attribute maps for Subgroup Test attributes--*/
data attrmap;
length textweight $10;
id='text'; value='1'; textcolor='white'; textsize=15; textweight='bold'; output;
id='text'; value='2'; textcolor='Black'; textsize=10; textweight='normal'; output;
run;
/*--Forest Plot--*/
options missing=' ';
/*ods listing style=htmlblue;*/
title j=l h=1.2 " test placebo";
/*ods listing gpath='c:\temp\' image_dpi=400;*/
/*ods graphics / reset width=5in height=3in imagename='Subgroup_Forest_SG_94';*/
ods graphics / reset width=9.6in height=4.5in noborder noscale;
proc sgplot data=forest_subgroup_2 nowall noborder nocycleattrs dattrmap=attrmap noautolegend;
format text $txt.;
styleattrs axisextent=data;
refline ref / lineattrs=(thickness=22 color=grayee);
highlow y=obsid low=low high=high /lowcap=serif highcap=serif lineattrs=(color=black);
scatter y=obsid x=mean / markerattrs=(symbol=squarefilled size=8 color=black );
scatter y=obsid x=mean / markerattrs=(size=0) x2axis;
refline 0 / axis=x;
text x=xl y=obsid text=text / position=bottom contributeoffsets=none strip textattrs=(size=10);
yaxistable subgroup / location=inside position=left textgroup=id labelattrs=(size=10)
LABELJUSTIFY=left valueattrs=(size=10 )
textgroupid=text indentweight=indentWt;
yaxistable Count Percent Count_test Percent_test ci pvalue/ VALUEJUSTIFY=right
location=inside position=left labelattrs=(size=10) valueattrs=(size=10) pad=(right=15px) ;
yaxis reverse display=none colorbands=odd colorbandsattrs=(transparency=1) ;
xaxis display=(nolabel) values=(0 to 5 by 1);
x2axis label='ODDS' display=(noline noticks novalues) labelattrs=(size=10) ;
run;
I need to increase the distance mentioned with a red arrow.
Please find it in the attached file.
data forest_subgroup;
infile cards truncover expandtabs;
input Id Subgroup : $80. Count Percent : $40. Count_test Percent_test : $40. Mean Low High ci :$40. pvalue $;
indentWt=1;
ObsId=_n_;
datalines;
2 aa 332 6.35(3.45) 111 3.73(3.98) 2.62 1.85 3.39 2.62(1.85,3.39) <0.001
2 1~3 101 5.80(3.43) 36 3.75(4.38) 2.05 0.63 3.47 2.05(0.63,3.47) 0.005
2 4~7 120 6.30(3.69) 37 2.73(3.65) 3.58 2.21 4.95 3.58(2.21,4.95) <0.001
2 8~14 111 6.91(3.12) 38 4.69(3.75) 2.22 0.99 3.44 2.22(0.99,3.44) <0.001
2 <6 78 3.44(2.73) 37 1.31(2.79) 2.13 1.04 3.21 2.13(1.04,3.21) <0.001
2 >6 254 7.25(3.14) 74 4.94(3.95) 2.31 1.32 3.30 2.31(1.32,3.30) <0.001
2 bbb 162 6.32(3.79) 63 3.65(4.43) 2.67 1.50 3.83 2.67(1.50,3.83) <0.001
2 cc 170 6.38(3.09) 48 3.83(3.35) 2.55 1.54 3.56 2.55(1.54,3.56) <0.001
2 dd 298 6.41(3.22) 107 3.78(4.04) 2.64 1.78 3.49 2.64(1.78,3.49) <0.001
2 ee 364 6.23(3.36) 120 3.67(3.91) 2.56 1.78 3.35 2.56(1.78,3.35) <0.001
2 ff 104 5.77(3.39) 37 3.65(4.37) 2.12 0.53 3.71 2.12(0.53,3.71) 0.010
2 gg 135 6.23(3.56) 41 2.91(3.52) 3.32 2.07 4.57 3.32(2.07,4.57) <0.001
1 xxxxxx
2 ALL 125 6.62(3.08) 42 4.44(3.79) 2.19 1.03 3.34 2.19(1.03,3.34) <0.001
;
run;
data forest_subgroup;
set forest_subgroup;
indentWt=1;
ObsId=_n_;
run;
data forest_subgroup_2;
set forest_subgroup nobs=n end=last;
length text $20;
val=mod(_N_-1, 6);
/* if val eq 1 or val eq 2 or val eq 3 then ref=obsid;*/
if mod(obsid,2 )=0 then ref=obsid;
/*--Separate Subgroup headers and obs into separate columns--*/
indentwt=2;
if id=1 then indentWt=0;
output;
if last then do;
call missing (subgroup, count, percent, Count_test ,Percent_test, mean, low, high, ci,
indentwt, val, ref ,pvalue);
obsid=n+1;
xl=1; yl=n+1; text='P'; output;;
xl=4; yl=n+1; text='T'; output;
end;
run;
/*--Define Format with Unicode for the left and right arrows--*/
proc format;;
value $txt
"T" = "test better (*ESC*){Unicode '2192'x}"
"P" = "(*ESC*){Unicode '2190'x} placebo better";
run;
/*--Attribute maps for Subgroup Test attributes--*/
data attrmap;
length textweight $10;
id='text'; value='1'; textcolor='white'; textsize=15; textweight='bold'; output;
id='text'; value='2'; textcolor='Black'; textsize=10; textweight='normal'; output;
run;
/*--Forest Plot--*/
options missing=' ';
/*ods listing style=htmlblue;*/
title j=l h=1.2 " test placebo";
/*ods listing gpath='c:\temp\' image_dpi=400;*/
/*ods graphics / reset width=5in height=3in imagename='Subgroup_Forest_SG_94';*/
ods graphics / reset width=9.6in height=4.5in noborder noscale;
proc sgplot data=forest_subgroup_2 nowall noborder nocycleattrs dattrmap=attrmap noautolegend;
format text $txt.;
styleattrs axisextent=data;
refline ref / lineattrs=(thickness=22 color=grayee);
highlow y=obsid low=low high=high /lowcap=serif highcap=serif lineattrs=(color=black);
scatter y=obsid x=mean / markerattrs=(symbol=squarefilled size=8 color=black );
scatter y=obsid x=mean / markerattrs=(size=0) x2axis;
refline 0 / axis=x;
text x=xl y=obsid text=text / position=bottom contributeoffsets=none strip textattrs=(size=10);
yaxistable subgroup / location=inside position=left textgroup=id labelattrs=(size=10)
LABELJUSTIFY=left valueattrs=(size=10 )
textgroupid=text indentweight=indentWt;
yaxistable Count Percent Count_test Percent_test ci pvalue/ VALUEJUSTIFY=right
location=inside position=left labelattrs=(size=10) valueattrs=(size=10) pad=(right=15px) ;
yaxis reverse display=none colorbands=odd colorbandsattrs=(transparency=1) ;
xaxis display=(nolabel) values=(0 to 5 by 1);
x2axis label='ODDS' display=(noline noticks novalues) labelattrs=(size=10) ;
run;
This trick works well.
thank you !!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.