Hello,
I want to do a graph with my data : a table with cancer (4 types) and sexe (male or female), 1540 patients similar to this example :
/* Set the graphics environment */
goptions reset=all cback=white border htitle=12pt htext=10pt;
/* Create sample data */
data test;
input midpnt category $ count;
datalines;
1 cat1 60
1 cat2 40
2 cat1 30
2 cat2 70
3 cat1 80
3 cat2 20
;
run;
title1 'Subgroups for Each Midpoint Total 100%' ; /* Define a title for the graph */
axis1 label=none value=none; /* Suppress the group axis label and values */
axis2 label=(angle=90 'Percent') ; /* Angle the label for the response axis */
legend1 label=('Category') frame ; /* Define legend characteristics */
proc gchart data=test;
vbar midpnt / discrete subgroup=category
group=midpnt g100 nozero
freq=count type=percent /* ne pas mettre l’option freq si on a une table déjà prête*/
inside=percent width=20
gaxis=axis1 raxis=axis2
legend=legend1;
run;
quit;
I try with my data and I obtain the graph :
Can you help me ?
Here is my code :
title1 'Subgroups for Each Midpoint Total 100%' ; /* Define a title for the graph */
axis1 label=none value=none; /* Suppress the group axis label and values */
axis2 label=(angle=90 'Percent') ; /* Angle the label for the response axis */
legend1 label=('Category') frame ; /* Define legend characteristics */
proc gchart data=denis.fusion;
where sexe ne "NA";
vbar cancer/ discrete subgroup=sexe
group=cancer g100
inside=percent width=20
gaxis=axis1 raxis=axis2
legend=legend1;
run;
quit;
Thank you for your help.
Nathalie
Removing count and updating the variable names worked for me...
*calculate percentages for stacked 100% bar chart;
proc freq data=essai noprint;
where sexe ne 'NA';
table cancer*sexe / out=want outpct ;
run;
*convert to percent for easier display;
data want;
set want;
pct_row = pct_row/100;
format pct_row percent12.1;
run;
*graph data;
title 'My Custom Graph Title';
proc sgplot data=want;
vbarparm category=cancer response=pct_row / group=sexe groupdisplay=stack seglabel;
yaxis '';
run;
SGPLOT is a better option these days.
data test;
input midpnt category $ count;
datalines;
1 cat1 60
1 cat2 40
2 cat1 30
2 cat2 70
3 cat1 80
3 cat2 20
;
run;
*calculate percentages for stacked 100% bar chart;
proc freq data=test noprint;
table midpnt*category / out=want outpct ;
weight count;
run;
*convert to percent for easier display;
data want;
set want;
pct_row = pct_row/100;
format pct_row percent12.1;
run;
*graph data;
title 'My Custom Graph Title';
proc sgplot data=want;
vbarparm category=midpnt response=pct_row / group=category groupdisplay=stack seglabel;
run;
See options here for customizing the graphics further
https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatproc/n0mc5dtithid5mn13c54dlgaceq3.htm
Thank you for your response, but I can't run the program because my table of data has no count. I had put an example that I want adapt to my data.
If I run your code with my data, I obtain :
proc freq data= denis.fusion noprint;
table cancer * sexe /out = want outpct;
weight count;
run;
1 proc freq data= denis.fusion noprint;
2 table cancer * sexe /out = want outpct;
3 weight count;
ERROR: Variable COUNT not found.
4 run;
Since your Yaxis is going to 600 percent then your data is incorrect for the type of graph you are attempting.
So share the actual data you are attempting to graph, not a made up example with different variables with different ranges of values.
Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the </> icon or attached as text to show exactly what you have and that we can test code against.
Thank you for your response.
I try to do the graph in my first post.
I give you my table of data with 3 variables id, sexe and cancer (4 types).
For sexe, NA is unknown.
Thank you for your help.
I work with SAS 9.4.
Removing count and updating the variable names worked for me...
*calculate percentages for stacked 100% bar chart;
proc freq data=essai noprint;
where sexe ne 'NA';
table cancer*sexe / out=want outpct ;
run;
*convert to percent for easier display;
data want;
set want;
pct_row = pct_row/100;
format pct_row percent12.1;
run;
*graph data;
title 'My Custom Graph Title';
proc sgplot data=want;
vbarparm category=cancer response=pct_row / group=sexe groupdisplay=stack seglabel;
yaxis '';
run;
Hello,
Thank you very much. It is OK.
😊
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.