Obsidian | Level 7

Calculate the necessary height of a graph

I've got a couple of different barchartparm -templates used by a report. All resulting graphs are horizontal barcharts but some are grouped and some are not.

I need for all the bars in the different graphs in the report to have the same thickness.

I'm working om a macro that sets the height of each graph depending on the data sent to the template at runtime (How many groups, how many category values). I'm having a bit of trouble getting it right though.

Looking for tips/ideas or possibly a detailed paper on how sas manages/divides the space available?

5 REPLIES 5
Super User

Re: Calculate the necessary height of a graph

Since the basic parameter that you would set is BARWIDTH in BARCHARTPARM statement, which

specifies the width of a bar as a ratio of the maximum possible width. If you would be calculating a number of "graph heights"  for different graphs you would be calculating a different BARWIDTH for each size graph, requiring as a minimum the exact number of bars that will appear in each graph and calculating for multiple graphs my get quite tedious to manage. How many different graphs are you talking, with how many bars each?

Personally I find that somewhat distracting, having many graphs of different sizes. I would be strongly tempted to settle on one size or possibly two if at all practical so there are fewer things to try to keep track of.

If the primary concern is the bar thickness you might consider using a VECTOR plot instead with a origin of your axis (vertical or horizontal) which would require adding an xorigin yorigin pair for each bar. That supports either the LINEATTRS with a thickness attribute or the LINETHICKNESSRESPONSE= option that lets you use a variable to control thickness as a specified dimension. You would use ARROWHEADS=False to not display arrows.

If this is for publication you may run into graph size rules to consider first before even going down this path.

Meteorite | Level 14

Re: Calculate the necessary height of a graph

One way to do this automatically is to use the SGPANEL procedure.  The PANELBY statement has the option - PROPORTIONAL.  This is useful for discrete chart case, and each panel in the graph is sized differently to maintain the same bar width.

You can also set the ROWS option to output only one row per output graph.  You just have to set up your data  with a classification variable.  Maybe you can leverage this to create your graphs.  Just a thought...

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=grstatproc&docsetTarget=n...

Meteorite | Level 14

Re: Calculate the necessary height of a graph

Are you using SAS/Graph (gchart), or ODS Graphics (sgplot), or other?

Obsidian | Level 7

Re: Calculate the necessary height of a graph

SAS/Graph

Meteorite | Level 14

Re: Calculate the necessary height of a graph

If you're using SAS/Graph (proc gchart), then I don't think the solutions posted so far will work for you.

Discussion stats
• 5 replies
• 457 views
• 1 like
• 4 in conversation