I have a set of data which consists of different ethnic groups and their feedback in a survey. I want to plot their responses by groups but the group size is different by the ethnic groups. So I want to plot the percent of frequency using the individual group total instead of the whole population in the survey. Currently I use the group feature in SAS to plot but that really doesn't represent the actual picture. Here's an example of the code:
title "Were you satifisfied with your trip?";
proc sgplot data= sasdata.cruise;
yaxis label= "Percent of Frequency";
vbar Q156_1/group=Q100 groupdisplay=cluster stat=percent datalabel ;
XAXIS discreteorder=unformatted DISPLAY=(NOLABEL);
run;
quit;
Thanks in advance.
Kathie
Calculated it before PROC SGPLOT .
data have;
set sashelp.heart;
run;
proc sql;
create table want as
select bp_status,Weight_Status,count(*)/
(select count(*) from have where Weight_Status=a.Weight_Status)
as percent format=percent8.2
from have as a
where bp_status is not missing and Weight_Status is not missing
group by bp_status,Weight_Status ;
quit;
proc sgplot data=want;
vbar bp_status/group=Weight_Status groupdisplay=cluster response=percent nostatlabel datalabel;
run;
Try adding the PCTLEVEL= Group to the VBAR statement if you want percentages calculated using the Group total.
@katslau wrote:
That didn't quite do what I want. It's giving me the % breakdown among the ethnic groups with one type of response, not by ethnic groups. What I want is that all responses should add up to 100% within one ethnic groups across the graph.
Your initial problem statement is not very clear. You stated "So I want to plot the percent of frequency using the individual group total instead of the whole population in the survey."
You did not say what 'individual group' you wanted.
I think that you will likely need to summarize your data with another procedure before plotting, likely with Proc Freq creating an output data to get the percentages you want and then use a VBARPARM.
Calculated it before PROC SGPLOT .
data have;
set sashelp.heart;
run;
proc sql;
create table want as
select bp_status,Weight_Status,count(*)/
(select count(*) from have where Weight_Status=a.Weight_Status)
as percent format=percent8.2
from have as a
where bp_status is not missing and Weight_Status is not missing
group by bp_status,Weight_Status ;
quit;
proc sgplot data=want;
vbar bp_status/group=Weight_Status groupdisplay=cluster response=percent nostatlabel datalabel;
run;
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!
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.