Data visualization with SAS programming

Plotting proportions by groups

Regular Contributor
Posts: 180

Plotting proportions by groups

Hello all,


I have a data looking roughly like this:


Event: 0/1

Group: G1 / G2

AgeBin: 20-30/30-40/40-50/...


I want to plot the proportion of the event (proportion of 1's) for each group, by age bin. I though to put the age bins on the x-axis, the proportion on the y-axis, and for each age bin, to plot twp points, maybe with different shapes of markers, one for each group, and then I can see what happens to the difference between the groups when the age changes.


1. How do I do that ? The data I specified is my variables as they are. I guess I need sgplots, but not sure how to do this task, it doesn't look straightforward. 

2. Is there a better representation that can suit my data ?


Thank you in advance !

SAS Employee
Posts: 980

Re: Plotting proportions by groups

Perhaps pre-summarize your data, and create a grouped bar chart, something like this?



Posts: 3,630

Re: Plotting proportions by groups

You can run PROC MEANS or some other procedure to get the proportions for each group and for each age group.

Then you can just use the SCATTER statement to plot the proportions against the age, using the GROUP= option to distinguish the groups.

/* make up some data */
data Have;
set sashelp.class sashelp.class sashelp.class;
event = rand("bernoulli", logistic(1 - age/10));

/* compute proportion for each age group and group */
proc means data=Have;
class sex age;
var event;
output out=out mean=Proportion;

proc sgplot data=out;
scatter y=proportion x=age / group=sex;

Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation