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
- /
- SAS - stacked bar graph

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

Highlighted
# SAS - stacked bar graph

Options

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

10-02-2017 03:20 PM

Hi community members,

I was trying to make a stacked bar graph but I am not sure why one of the categories for two variables reveresed their place. Please see the picture attached herewith. my code to produce the chart is:

ods graphics on;

PROC SGPLOT DATA = stress;

VBAR variable / RESPONSE = percent GROUP = endorsed STAT = SUM SEGLABEL CATEGORYORDER = RESPDESC;

YAXIS GRID LABEL = "Percentage";

RUN;

ods graphics off;

Thanks,

Pooja

Accepted Solutions

Solution

10-02-2017
04:26 PM

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

Posted in reply to Pooja2

10-02-2017 03:40 PM

I have a hunch about why this happened, but I cannot verify that without your data. However, I think I have determined that your data is pre-summarized, based on the graph and the options you used. Therefore, try this as a workaround:

```
proc sort data=stress out=stress2; by descending group descending percent; run;
ods graphics on;
PROC SGPLOT DATA = stress2;
VBARPARM category=variable RESPONSE = percent / GROUP = endorsed SEGLABEL groupdisplay=stack;
YAXIS GRID LABEL = "Percentage";
RUN;
ods graphics off;
```

Hope this helps!

Dan

All Replies

Solution

10-02-2017
04:26 PM

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

Posted in reply to Pooja2

10-02-2017 03:40 PM

I have a hunch about why this happened, but I cannot verify that without your data. However, I think I have determined that your data is pre-summarized, based on the graph and the options you used. Therefore, try this as a workaround:

```
proc sort data=stress out=stress2; by descending group descending percent; run;
ods graphics on;
PROC SGPLOT DATA = stress2;
VBARPARM category=variable RESPONSE = percent / GROUP = endorsed SEGLABEL groupdisplay=stack;
YAXIS GRID LABEL = "Percentage";
RUN;
ods graphics off;
```

Hope this helps!

Dan

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

Posted in reply to DanH_sas

10-02-2017 04:28 PM

Thanks Dan. That was awesome and easy fix. I had done freq analysis for each variable and then summarized them in a table to produce stacked bar graph. I am not sure how to do it otherwise. I am still learning SAS and loving it for analysis at work at school both.

Thanks a lot!