BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ammarhm
Lapis Lazuli | Level 10

I am trying to modify the excelent code suggestes by Sanjay Matange  to produce a forest plot:

 

The link to the code is:

http://blogs.sas.com/content/graphicallyspeaking/2013/01/06/forest-plot-with-sas-9-3/

 

I am using that code to prodice a Forest plot for meta-analysis of multiple studies. I am trying to modify the code so that the size of the square in the middle of the odds ratio bar would be proportional to the "weight" of the study. I ahave therefore created an aditional variable in the studies table with numerical values generated from the weight of the study to be used at the size of the square

 


   highlowplot y=obsid low=low high=high / CLIPCAP=true; 
          scatterplot y=obsid x=mean /  markerattrs=(symbol=squarefilled size=WT color=green);
referenceline x=1;

This is however giving me an error:

 

ERROR 772-580: Syntax error: expecting a constant or a dynamic.

 

Is there anyway of solving this problem? I read that you could use DATTRMAP but I havent manage to incorporate it into to the code. Any help is greatly appreciated

Kind regards

AM

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

What version of SAS are you running? In SAS 9.4m1 and beyond you can use the MARKERSIZERESPONSE= option (in conjunction with MARKERSIZEMIN= and MARKERSIZEMAX=).

 

If your version of SAS is older, then use the BUBBLEPLOT statement

 

If your version of SAS is ancient, you can use the ELLIPSEPARM statement, but that requires some pre-computing of values and is harder than the other options.

 

 

View solution in original post

17 REPLIES 17
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, just a guess here.  I think you might need to pre-cacluate the mean and add it to your dataset as a variable, then use that variable in the x= statement.

ammarhm
Lapis Lazuli | Level 10

Thank you for the kind reply

To further explain, the problem is in the size=WT part, this statement needs a numerical, so if I change to 

size=15

then the plot works but all the studies would have the same symple weight, which I am trying to change

Thanks

Rick_SAS
SAS Super FREQ

What version of SAS are you running? In SAS 9.4m1 and beyond you can use the MARKERSIZERESPONSE= option (in conjunction with MARKERSIZEMIN= and MARKERSIZEMAX=).

 

If your version of SAS is older, then use the BUBBLEPLOT statement

 

If your version of SAS is ancient, you can use the ELLIPSEPARM statement, but that requires some pre-computing of values and is harder than the other options.

 

 

ammarhm
Lapis Lazuli | Level 10

Thanks Rick, that solved it!

Kind regards

AM

ammarhm
Lapis Lazuli | Level 10

Is there a way to do similar modification to the shape and colour of the marker?

ie by having a column with shape names and a column with colours for each study?

Kind regards

 

Rick_SAS
SAS Super FREQ

These are discrete attributes, so presumably you have a grouping variable. You can specify the GROUP= option on the SCATTERPLOT statement to get the defaul symbols/colors fo groups in the current style.

 

There are then tons of ways to modify colors and symbols for groups: syles, style attributes, dattrmaps, etc. Sanjay has many blogs on this topic.   To get started, read the doc section "Key concepts for using attribute maps."

 

ammarhm
Lapis Lazuli | Level 10

Thanks

As you mentioned there are many ways described in the blogs. Implementing them is not straight forward since the forest plot coding I am refering to uses proc template

Would you please suggest a simple way of using colour coding from a column or even grouping by a column content to modify the marker colour and shape?

Thanks again

Rick_SAS
SAS Super FREQ

I already suggested that you use attribute maps. Marker colors and shapes are linked to the GROUP= variable.  

 

I recommend that you look at the doc and try to build what you need. If you get stuck, post the code and some sample data and someone might be able to help.

Jay54
Meteorite | Level 14

Rick has answered most of your questions,, however this graph was made using SAS 9.3 features and GTL.  Since then, new statements have been introduced including AXISTABLE, etc with SAS 9.4, making this graph much easier.to create.  Also, GTL scatter plot supports SIZERESPONSE.  If you have SAS 9.4, this will be easier.  

 

Also, often users want to show the weight by only changing the marker width, and not height (which can run into each other).  So, a HighLow bar can be used for that purpose.  This will also work with SAS 9.3.

 

Please see link to article below.  Same can be done using GTL if you need more features.

http://blogs.sas.com/content/graphicallyspeaking/2016/05/30/ctspedia-clinical-graphs-subgrouped-fore...

 

ammarhm
Lapis Lazuli | Level 10

Dear Sanjay and Rick

Thank you for your suggestions, I managed to implement them now succeesfully, in the proc template I have added the following:

 

	 entrytitle 'id';
discreteattrmap name='colors' / ignorecase=true;
         value '1' / markerattrs=(color=blue symbol=squarefilled );
         value '2' / markerattrs=(color=green symbol=diamond);
		  value '3' / markerattrs=(color=red symbol=diamondfilled);
     
      enddiscreteattrmap;
      discreteattrvar attrvar=classfill var=id attrmap='colors';

Then for the plot itself in the same template:

   highlowplot y=obsid low=low high=high / CLIPCAP=true; 
          scatterplot y=obsid x=mean /  markersizeresponse=wt markersizemin=10 markersizemax=30 group=classfill;
    referenceline x=1;

However, as Sanjay mentioned, this is creating another problem: The markersizeresponce is affecting the hight as well as the width of the marker, is there a way to controll these individually? I would be more interested in correlating the width of the marker to the weight of the contrubuting study in the table

 

Thank you

Jay54
Meteorite | Level 14

I don't see a way to scale only the width of the scatter markers using MarkerSizeResponse.

 

Please see the 2nd example in the article below.  This shows how you can use the HighLow plot to display markers with width scaled by the some variable.  One note to keep in mind is the displayed marker widths may be affected by the log axis when the data range has large variation.  If this is important, the width calculations for the HighLow could be adjusted to take the log transform into account.

 

http://blogs.sas.com/content/graphicallyspeaking/2012/02/01/forest-plot-using-sgplot-procedure/

 

ammarhm
Lapis Lazuli | Level 10

Hi Sanjay

Excellent suggestion as usual

SAS has celarly a lot of power creating good graphs, including Forest plots.

PLease look at the examples in the following article which were made by sas, there are several Forest plots

http://www.bmj.com/content/341/bmj.c4737.full.pdf

I wonder if you can think of a way of producing the "verically squished" diamoned figure used in the plots?

 

Kind regards

Ammar

 

Jay54
Meteorite | Level 14

Two possibilities come to mind.

  • Use the SYMBOLCHAR or SYMBOLIMAGE to create a new marker symbol of the shape you want, filled on empty.
  • Display the squished diamond as a POLYGON plot.

http://blogs.sas.com/content/graphicallyspeaking/2014/01/26/more-symbols-you-say/

http://blogs.sas.com/content/graphicallyspeaking/2013/12/24/new-polygon-plot/

ammarhm
Lapis Lazuli | Level 10

THanks again Sanjay, excellent answers and guidance

 

Interestingly, new solutions create new challenges, useing the highlow plot to draw a bar according to the weight of the study works great. However, I ended up being unable to control the height of the bar which became disproportional in the graph, see attached figure.

I looked up any attributes that I could use to adjust the height but couldnt, any suggestions please?

Kind regards

AM

 


Forest.png

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 17 replies
  • 5420 views
  • 7 likes
  • 4 in conversation