Data visualization with SAS programming

Plotting proportions by groups

Reply
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?

 

http://robslink.com/SAS/democd75/holiday_shopping_plans.htm

http://robslink.com/SAS/democd75/holiday_shopping_plans_info.htm

 

holiday_shopping_plans.png

SAS Super FREQ
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));
run;

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

proc sgplot data=out;
WHERE _TYPE_=3;
scatter y=proportion x=age / group=sex;
run;


Ask a Question
Discussion stats
  • 2 replies
  • 477 views
  • 0 likes
  • 3 in conversation