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

Hi all,

 

This is my first time posting to the forum but I have found it incredibly helpful in my journey of learning SAS so I thought I would try posting a question I have. I found one similar question in the forum from a few years ago but there was no solution in the thread. I am using SAS 9.4 and am trying to create a clustered bar chart (using sgplot) with a table of values directly below. Using xaxistable, I am able to get the desired result with the exception of one small formatting issue: gridlines. I am not looking to add gridlines to the graph, but to the table below the graph. I inserted a sample dataset and code for what I am doing as well as pictures of the resulting graph and desired formatting changes.

 

Thanks! 

data sampledata;
input percent 4.1 gender $ group $;
datalines;
15.8 M 1
27.4 M 2
19.6 M 3
25.2 F 2
28.1 F 1
29.6 F 3
;
run;

proc sgplot data=sampledata;
vbar gender / group=group groupdisplay=cluster datalabel datalabelfitpolicy=none response=percent;
xaxis values=("M" "F") display=(nolabel) 
valuesdisplay=("Male" "Female") fitpolicy=splitalways;
styleattrs datacolors=(CXFBFFB3 CX68CAB5 CX4376B3);
styleattrs datacontrastcolors=(Black);
xaxistable percent/ pad=15;
run;

AshleyS_0-1657035539482.pngAshleyS_1-1657035553924.png

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ghosh
Barite | Level 11

You could use ODS layout and proc report to add the table. 

Here is a quick and dirty solultion.

ods layout gridded;
 
ods region style={bordercolor=black borderstyle=solid borderwidth=.25pt};

ods graphics / noborder;
proc sgplot data=sampledata;
vbar gender / group=group groupdisplay=cluster datalabel datalabelfitpolicy=none response=percent;
xaxis values=("M" "F") display=(nolabel) 
valuesdisplay=("Male" "Female") fitpolicy=splitalways;
styleattrs datacolors=(CXFBFFB3 CX68CAB5 CX4376B3);
styleattrs datacontrastcolors=(Black);
/* xaxistable percent/ pad=15; */
run;

proc report data=sampledata nowd;
columns  group percent,gender;
define group / group style=[cellwidth=2cm just=c];
define gender / across '' order=data style=[cellwidth=7cm just=c] ;
define percent / analysis '' style=[cellwidth=7cm just=c];
run;

ods layout end;

ghosh_0-1657382320789.png

 

View solution in original post

5 REPLIES 5
Rick_SAS
SAS Super FREQ

I don't think there is an option to add a grid to an XAXISTABLE. I looked in the documentation for the XAXISTABLE statement and even looked at the AXISTABLE statement in the GTL. I do not see any options to draw a grid automatically.

 

 

AshleyS
Fluorite | Level 6

Thank you for looking into this, Rick. It seems that adding gridlines to the XAXISTABLE statement may not be a feature that is currently available then. 

Rick_SAS
SAS Super FREQ

Yes. That is my conclusion.

ghosh
Barite | Level 11

You could use ODS layout and proc report to add the table. 

Here is a quick and dirty solultion.

ods layout gridded;
 
ods region style={bordercolor=black borderstyle=solid borderwidth=.25pt};

ods graphics / noborder;
proc sgplot data=sampledata;
vbar gender / group=group groupdisplay=cluster datalabel datalabelfitpolicy=none response=percent;
xaxis values=("M" "F") display=(nolabel) 
valuesdisplay=("Male" "Female") fitpolicy=splitalways;
styleattrs datacolors=(CXFBFFB3 CX68CAB5 CX4376B3);
styleattrs datacontrastcolors=(Black);
/* xaxistable percent/ pad=15; */
run;

proc report data=sampledata nowd;
columns  group percent,gender;
define group / group style=[cellwidth=2cm just=c];
define gender / across '' order=data style=[cellwidth=7cm just=c] ;
define percent / analysis '' style=[cellwidth=7cm just=c];
run;

ods layout end;

ghosh_0-1657382320789.png

 

AshleyS
Fluorite | Level 6
Thank you so much, Ghosh!

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 1639 views
  • 7 likes
  • 3 in conversation