DATA Step, Macro, Functions and more

proc gchart (group % and overall % side by side)

Accepted Solution Solved
Reply
Contributor
Posts: 31
Accepted Solution

proc gchart (group % and overall % side by side)

I am creating a bar chart where I display 30 individual charts using the "by statement":

 

proc gchart data = analytic_file;

by group_id;

vbar age_category / type=percent;

run;

 

The above creates 30 individual charts (for each group) showing the age category percentages for each group_id (great!)

On each of the 30 charts, I want to show side by side 1) the age_category precentages for the group  AND 2) the overall percentages for the entire population (analytic_file, not grouped by groupid). Ex. There are 30% who are 18-25 in groupd A, and 45% who are 18-25 for the entire population.

 

How would I do this?


Accepted Solutions
Solution
‎03-03-2016 12:03 PM
Contributor
Posts: 31

Re: proc gchart (group % and overall % side by side)

I figure it out. I am using proc freq to come up with percentages for each of the groups individually:

 

http://blogs.sas.com/content/iml/2012/12/03/show-percentages-for-bar-charts-with-proc-sgplot.html

 

Then I am merging the output of the two datasets for two new variables: one for the percent overall, and one for the percent for the group.

View solution in original post


All Replies
Super User
Super User
Posts: 7,403

Re: proc gchart (group % and overall % side by side)

Well, advice one - move to sgplot/graph template language.  With this you can overlay as much as you want.  You can find examples for almost any type of graph here:

http://blogs.sas.com/content/graphicallyspeaking/

 

If you can't find what you want there then post some test data (datastep), and what the output should look like.

Contributor
Posts: 31

Re: proc gchart (group % and overall % side by side)

proc sgplot was defintely the way to go, and solved a couple of my other problems.

 

However, I still have the same questions. I want to overlay (or side by side) each of these 35 graphs generated with the by statement:

A)

proc sgplot data= analytic_cohort;
by pat_groupid;
vbar agecat_clinical;
run;

 

With the one graph generated by:

 

B)

proc sgplot data= analytic_cohort;
vbar agecat_clinical;
run;

 

B) contains the overall agecat_clinical for the entire population and I want that next to the age_cat clinical for the pat_groupid.

Regular Contributor
Posts: 234

Re: proc gchart (group % and overall % side by side)

Solution
‎03-03-2016 12:03 PM
Contributor
Posts: 31

Re: proc gchart (group % and overall % side by side)

I figure it out. I am using proc freq to come up with percentages for each of the groups individually:

 

http://blogs.sas.com/content/iml/2012/12/03/show-percentages-for-bar-charts-with-proc-sgplot.html

 

Then I am merging the output of the two datasets for two new variables: one for the percent overall, and one for the percent for the group.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 280 views
  • 0 likes
  • 3 in conversation