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

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;

Nathalie1_1-1665505032264.png

 

I try with my data and I obtain the graph :

Nathalie1_0-1665504887800.png

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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;

View solution in original post

8 REPLIES 8
Reeza
Super User

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

 

 

 

Nathalie1
Obsidian | Level 7

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;

Reeza
Super User
I used the example data set provided. It looks like the Count variable in your example data set does not exist in your data set or has a different name?
You should update the code to account for that variable name change or difference.

3 weight count;
ERROR: Variable COUNT not found.
Reeza
Super User
Making a WAG you can remove the WEIGHT statement from the code and it should work for you.
The summary data already had counts, it appears you're using raw data. But that's a guess - I can't see your data, variables or understand it's structure so I can only work off what's been shown.
ballardw
Super User

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.

Nathalie1
Obsidian | Level 7

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.

Reeza
Super User

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;
Nathalie1
Obsidian | Level 7

Hello,

 

Thank you very much. It is OK.

😊

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 8 replies
  • 1053 views
  • 5 likes
  • 3 in conversation