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

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

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

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

View solution in original post

2 REPLIES 2
DanH_sas
SAS Super FREQ

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

Pooja2
Fluorite | Level 6

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!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 842 views
  • 0 likes
  • 2 in conversation