turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS/GRAPH and ODS Graphics
- /
- Graphing Yes only by group

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-29-2016 10:15 AM - edited 02-29-2016 10:17 AM

I am trying create a graph that shows the row percent only for 2 groups and within the graph show 2-3 variables.. How do I do this?

I created an example in Excel which is attached as an image. I am hoping to do this in SAS, since I have a lot of graphs to create and also want to avoid copying and pasting numbers (so don't want any human error).

I have the raw data, so I will need to use proc freq to compute the percentages.

Accepted Solutions

Solution

02-29-2016
11:22 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Tpham

02-29-2016 10:38 AM

Okay, here is an example then. I agree with RW9 too, you need to drop the No data before you plot the graph.

data test;

input var$ group$ response$ result;

cards;

var1 group1 yes 0.7

var1 group2 yes 0.75

var1 group1 no 0.3

var1 group2 no 0.25

var2 group1 yes 0.35

var2 group2 yes 0.2

var2 group1 no 0.65

var2 group2 no 0.8

;

run;

proc sgpanel data = test;

where response = "yes";

panelby var;

vbar group / response = result group = response stat= mean;

run;

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Tpham

02-29-2016 10:22 AM

Hi,

What version of SAS do you have please? Can you provide the raw data or the data of the percentages please?

Thanks.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to djrisks

02-29-2016 10:24 AM

SAS 9.2, I can't provide the raw dataset.

I am looking for the general approach I should use so I can code this myself.

Solution

02-29-2016
11:22 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Tpham

02-29-2016 10:38 AM

Okay, here is an example then. I agree with RW9 too, you need to drop the No data before you plot the graph.

data test;

input var$ group$ response$ result;

cards;

var1 group1 yes 0.7

var1 group2 yes 0.75

var1 group1 no 0.3

var1 group2 no 0.25

var2 group1 yes 0.35

var2 group2 yes 0.2

var2 group1 no 0.65

var2 group2 no 0.8

;

run;

proc sgpanel data = test;

where response = "yes";

panelby var;

vbar group / response = result group = response stat= mean;

run;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Tpham

02-29-2016 10:27 AM

Well, the simplest way would be to have a datastep before it which drops the No data, then its just a barchart by group.

Alternatively, a stacked barchart, with the no group given color white would also work. You can find many examples of all types of graphs here:

http://blogs.sas.com/content/graphicallyspeaking/?s=stacked

I have filtered for stacked, but there are many examples.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-29-2016 10:35 AM

If I drop the No data, wouldn't the % be impacted?

Since I want the percentages of "Yes" within the variable for that group...

Is there a way I can make SAS create a bar graph of just numbers? I am thinking if I can use proc freq with an out= option and keep only the percentage of yes within that dataset and graph that?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Tpham

02-29-2016 10:40 AM

You can calculate the percentages using all the data, and then drop the "No data" before you produce the barchart.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Tpham

02-29-2016 10:41 AM

So what does your data look like, I assumed from what you had posted you already had percentages, but from the below, you seem to be calculating percentage from data. Can you clarify what your data looks like, if you already have the percentages then @djrisks solution should work.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-29-2016 10:45 AM - edited 02-29-2016 10:50 AM

So my data looks something like this (sample data, not actual). where 1=yes and 2=no and then a group variable 1/2. All these have formats (so var, yes/no and group with group names)

So in this case, I want to calculate the row percentage of each variable for each group and then graph only the %yes

The percentage that I have calculated in my excel graph example would be from the proc freq results. I have about 200 vars, of course now 200 variables would be on one graph). So I am wondering is there a way to streamline/automate this?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Tpham

02-29-2016 10:55 AM

@Tpham The percents are not impacted because there is only 1 value for each column and if you take the mean or sum of a single number the value is the single number so it graphs the way you expect.

Essentially you're pre-calculating your values and using the above logic to produce your graph.

The example from @djrisks demonstrates this, though you'll need to customize the plot.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Tpham

02-29-2016 10:52 AM

What about this one - it uses GCHART but allows for groups and subgroups.

http://robslink.com/SAS/democd7/col1.htm

http://robslink.com/SAS/democd7/col1.sas