BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
YYK273
Obsidian | Level 7

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.41467_2023_42581_Fig6_HTML.png

 

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

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
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;

Ksharp_0-1714793592979.png

 

View solution in original post

2 REPLIES 2
Ksharp
Super User

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;

Ksharp_0-1714787825098.png

 

Ksharp
Super User
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;

Ksharp_0-1714793592979.png

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1610 views
  • 4 likes
  • 2 in conversation