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

Hi,

I'm totally new to SAS. I want to display a barchart of a question from a survey which can have multiple answers, so I have a table of the different treatments that were selected by the participants and their counts. I used the new define statgraph feature to generate the barchart instead of using the stat vertical bar chart. I used the template from the documentation. I would like to NOT display the "treatment" in the xaxis because the labels of the variables are self-explanatory. Below is what I have. What code do I need to have to tell it not display the label?

Thanks.

 

proc template;
define statgraph barchart;
begingraph;
entrytitle "What cacner treatment(s) have you had?";
layout overlay;
barchart category=treatment response=frequency /
stat=mean orient=horizontal;
endlayout;
endgraph;
end;

proc sgrender data=sasdata.augtx2021 template=barchart;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
djrisks
Barite | Level 11

Hi @katslau, it helps if you also include your data and/or your graph when you make a post.

 

If you do not want to display the treatment on the x-axis then you can use the DISPLAY option to select the parts of the XAXIS that you want to display. Try this code below:

 

proc template;
  define statgraph barchart;
    begingraph;
      entrytitle "What cancer treatment(s) have you had?";
      layout overlay / XAXISOPTS = (DISPLAY=(LINE TICKS TICKVALUES));
        barchart category=treatment response=frequency /
          stat=mean orient=horizontal;
      endlayout;
  endgraph;
end;

proc sgrender data=sasdata.augtx2021 template=barchart;
run;

View solution in original post

6 REPLIES 6
djrisks
Barite | Level 11

Hi @katslau, it helps if you also include your data and/or your graph when you make a post.

 

If you do not want to display the treatment on the x-axis then you can use the DISPLAY option to select the parts of the XAXIS that you want to display. Try this code below:

 

proc template;
  define statgraph barchart;
    begingraph;
      entrytitle "What cancer treatment(s) have you had?";
      layout overlay / XAXISOPTS = (DISPLAY=(LINE TICKS TICKVALUES));
        barchart category=treatment response=frequency /
          stat=mean orient=horizontal;
      endlayout;
  endgraph;
end;

proc sgrender data=sasdata.augtx2021 template=barchart;
run;
katslau
Fluorite | Level 6

Yes, that works.

 

Thank you.

katslau
Fluorite | Level 6

Hi @djrisks ,

One more question (it's probably very trivia to you): If I want to add the value of the counts to the bar (i.e. at the top of the bar), how would I do that? Something like this chart:

katslau_1-1629268136356.png

I attached the table for the treatment data.

Thanks again.

 

 

 

 

djrisks
Barite | Level 11

Hi @katslau

Thanks for attaching the data! 😊

To add the value of the counts to the bar, you can use the BARLABEL=TRUE option within the BARCHART statement. Please see the example code below:

 

proc template;
  define statgraph barchart;
    begingraph;
      entrytitle "What cancer treatment(s) have you had?";
      layout overlay / YAXISOPTS = (DISPLAY=(LINE TICKS TICKVALUES));
        barchart category=treatment response=frequency /
          stat=mean orient=horizontal BARLABEL=true;
      endlayout;
  endgraph;
end;

proc sgrender data=sasdata.augtx2021 template=barchart;
run;

 

 

katslau
Fluorite | Level 6

Yes, that works. I tried that before emailing you and it didn't work. It must be because I didn't put the label at the appropriate place...

 

Thanks.

sbxkoenk
SAS Super FREQ

Hello @katslau ,

 

using a template (with PROC TEMPLATE + PROC SGRENDER) is absolute overkill for the required plot.

 

I would use a HBAR or VBAR statement in PROC SGPLOT (SG = Statistical Graphics).

 

Submit the below code to find out how this can be done:

proc sgplot data=sashelp.heart;
  title "Smoking_Status 'Distribution'";
  hbar Smoking_Status;
  keylegend / location=inside position=topright;
  yaxis display=(nolabel);
run;
title;

Kind regards,

Koen

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
  • 6 replies
  • 1435 views
  • 7 likes
  • 3 in conversation