BookmarkSubscribeRSS Feed
BlueNose
Quartz | Level 8

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 !

2 REPLIES 2
GraphGuy
Meteorite | Level 14

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

Rick_SAS
SAS Super FREQ

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;


sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 3147 views
  • 0 likes
  • 3 in conversation