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

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?

1 ACCEPTED SOLUTION

Accepted Solutions
wave43
Obsidian | Level 7

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

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

wave43
Obsidian | Level 7

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.

wave43
Obsidian | Level 7

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.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 4 replies
  • 1878 views
  • 0 likes
  • 3 in conversation