BookmarkSubscribeRSS Feed
Fluorite | Level 6

I am trying to barchart using proc sgrender. My dataset has variable called ID with 2 different values for time ,group and reasons. To plot data points correctly I formatted ID in such a way that it has values _n_ according to the data.

ID  TIME  group  id_ reasons  length  stat  statvar

1    5        A         1     xxx         6         35       age

1    6        B         2     yyy         7         asian   ethinic

                                                            country  xxx

                                                             xxx        yyy

I calculated length variable from time so that that graph plot value just above the bar . length = time+1;

I want to create bar chart in such a way that group A and B gets different colors for the corresponding ID and there shouldn't be any space between bars.  The code I used is

proc template;

define statgraph barcolors;

dynamic xvar yvar;


discreattrmaps name='catcolors'/ignorecase=true




discreattrmaps attrvars=group var=group attrmap='catcolors';

layout overlay/



barchartparam x = id_ y = time/primary=yes  groups = group groupdisplay = cluster name='colors'

scatterplot x =id_ y = length/markerattrs=(size=5 weight=bold)group=reasons;

The problem I have is since id_ has different value for same ID , it create a space between bars. If I use ID instead of id_ in scatterplot then all the reasons goes to first bar not to corresponding bar. How can I tell SAS not to put space between bars for each ID?

I am also trying to put a table under graph. since there are 2 bars for each ID, graph is having trouble to put values under each ID in the table. Is there any solution for this too?

boxplot x= id_  y = stat/class=varstat;

Super User

Without examples of your data it is a bit difficult to make complete suggestions.

I would recommend visiting

or and see if you find something that looks like what you want to do and examine that code.

Fluorite | Level 6

Thanks! I used the code from the following PROC_SGRENDER.html

It worked fine . Another question I have is when I use scatter plot over barchart to put points on the top of each bar, symbols goes to corner of bar instead of middle of each bar if there are 2 bars per ID. If there is only one bar per id then the symbol goes to the center of bar

ID  TIME  group  id_ reasons  length 

1    5        A         1     xxx         6        

1    6        B         2     yyy         7

SCATTERPLOT X = ID Y =LENGTH/group = reasons markerattrs(size = 2 weight=bold)

Is there anyway to tell SAS to put symbols in the center of each bars?

Super User

You might try MARKERCHARACTER with a symbol font set using MARKERCHARACTERATTRS as the online help says this centers strings. If A B etc are acceptable for symbols it should work fine instead fo markerattrs.

Meteorite | Level 14

Why can't you use proc SGPLOT with VBAR with GroupDisplay=Cluster and Data Label?

You can use BarWidth=1 to not get spaces between bars.  If you attach your full program with data, it is easier to help.



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg



Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 4 replies
  • 3 in conversation