Hi SAS Community,
I've been trying to create a grouped forest plot in SAS, but so far, I've only been able to find resources on how to create a single forest plot. However, my requirement is to combine two forest plots into one, similar to the attached sample plot.
I'm wondering if anyone could offer some guidance on how to achieve this. Should I use proc sgplot
or proc template
for this purpose? Currently, I'm using the proc sgplot
code provided in this post: CTSPedia Clinical Graphs - Subgrouped Forest Plot.
Any insights or examples you could share would be greatly appreciated!
Thank you in advance!
Jess
data have;
call streaminit(123);
do year=1 to 2;
do id=1 to 10;
if id in (3:4 6 8 10) then new_id=id;
else new_id=.;
mean=rand('uniform',-0.1,0.1);
error=rand('uniform',-0.05,0.05);
lower=mean-error;
upper=mean+error;
output;
end;
end;
run;
proc sgpanel data=have ;
panelby year/spacing=0;
scatter x=mean y=id/xerrorlower=lower xerrorupper=upper;
rowaxis type=discrete offsetmin=0.05 offsetmax=0.05 ;
refline 0/axis=x lineattrs=(pattern=dash);
refline new_id/axis=y lineattrs=(thickness=40) transparency=0.8;
run;
That is what PROC SGPANEL supposed to do .
data have;
call streaminit(123);
do year=1 to 2;
do id=1 to 10;
if id=1 then new_id=1;
else if id in (2:4) then new_id=2;
else if id=5 then new_id=5;
else if id=6 then new_id=6;
else if id in (7:8) then new_id=7;
else new_id=id;
mean=rand('uniform',-0.1,0.1);
error=rand('uniform',-0.05,0.05);
lower=mean-error;
upper=mean+error;
output;
end;
end;
run;
proc sgpanel data=have;
panelby year;
scatter x=mean y=id/xerrorlower=lower xerrorupper=upper;
rowaxis type=discrete offsetmin=0.05 offsetmax=0.05 ;
refline 0/axis=x lineattrs=(pattern=dash);
refline new_id/axis=y discreteoffset=0.5;
run;
data have;
call streaminit(123);
do year=1 to 2;
do id=1 to 10;
if id in (3:4 6 8 10) then new_id=id;
else new_id=.;
mean=rand('uniform',-0.1,0.1);
error=rand('uniform',-0.05,0.05);
lower=mean-error;
upper=mean+error;
output;
end;
end;
run;
proc sgpanel data=have ;
panelby year/spacing=0;
scatter x=mean y=id/xerrorlower=lower xerrorupper=upper;
rowaxis type=discrete offsetmin=0.05 offsetmax=0.05 ;
refline 0/axis=x lineattrs=(pattern=dash);
refline new_id/axis=y lineattrs=(thickness=40) transparency=0.8;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.