## Modifying Forest Plot by Sanjay Matange to display study weight boxes

Solved
Regular Contributor
Posts: 169

# Modifying Forest Plot by Sanjay Matange to display study weight boxes

[ Edited ]

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

Accepted Solutions
Solution
‎08-12-2016 09:13 AM
SAS Super FREQ
Posts: 3,907

## Re: Modifying Forest Plot by Sanjay Matanga to display study weight boxes

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.

All Replies
Super User
Posts: 8,634

## Re: Modifying Forest Plot by Sanjay Matanga to display study weight boxes

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.

Regular Contributor
Posts: 169

## Re: Modifying Forest Plot by Sanjay Matanga to display study weight boxes

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

Solution
‎08-12-2016 09:13 AM
SAS Super FREQ
Posts: 3,907

## Re: Modifying Forest Plot by Sanjay Matanga to display study weight boxes

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.

Regular Contributor
Posts: 169

## Re: Modifying Forest Plot by Sanjay Matanga to display study weight boxes

Thanks Rick, that solved it!

Kind regards

AM

Regular Contributor
Posts: 169

## Re: Modifying Forest Plot by Sanjay Matanga to display study weight boxes

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

SAS Super FREQ
Posts: 3,907

## Re: Modifying Forest Plot by Sanjay Matanga to display study weight boxes

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."

Regular Contributor
Posts: 169

## Re: Modifying Forest Plot by Sanjay Matanga to display study weight boxes

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

SAS Super FREQ
Posts: 3,907

## Re: Modifying Forest Plot by Sanjay Matanga to display study weight boxes

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.

SAS Super FREQ
Posts: 1,227

## Re: Modifying Forest Plot by Sanjay Matanga to display study weight boxes

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...

Regular Contributor
Posts: 169

## Re: Modifying Forest Plot by Sanjay Matanga to display study weight boxes

[ Edited ]

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

SAS Super FREQ
Posts: 1,227

## Re: Modifying Forest Plot by Sanjay Matanga to display study weight boxes

[ Edited ]

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/

Regular Contributor
Posts: 169

## Re: Modifying Forest Plot by Sanjay Matanga to display study weight boxes

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

SAS Super FREQ
Posts: 1,227

## Re: Modifying Forest Plot by Sanjay Matanga to display study weight boxes

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/

Regular Contributor
Posts: 169

## Re: Modifying Forest Plot by Sanjay Matanga to display study weight boxes

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

☑ This topic is solved.