Hello,
Is there any way to display the ROW PCT (ROW PERCENT generated in proc freq) on top of the bars (VBAR) in the bar graph instead of the total percentage? I used PROC SGPLOT and the option STAT = PERCENT. However, it displays the total percent, and I want to display the row percent above the bars. I used datalabel option to display the statistic.
Here is the sample of the code;
proc sgplot data = learn.data_main;
vbar Place / response = check stat = percent
group = Ins groupdisplay = cluster datalabel ;
run;
Does anyone have a suggestion? Thanks in advance! * I use SAS 9.4 in windows.
Hey everyone!
I actually wanted to display the row percent which I obtained through proc freq. I figured it out. I actually used the PCTLEVEL = GROUP option in the proc sgplot statement. This worked! it displayed the row percentages of the grouped variable which is what I wanted to do. Thanks, everyone!
proc sgplot data = learn.data_main pctlevel = group;
vbar Place / response = check stat = percent
group = Ins groupdisplay = cluster datalabel ;
run;
Have you tried this?
Note: Using uppercase for user-defined strings would make your code a lot more legible (and avoid having to specify what is what as I was forced to do in my previous reply).
proc sgplot data = LEARN.DATA_MAIN;
vbar PLACE / response=CHECK stat=percent group=INS groupdisplay=cluster datalabel=ROW_PERCENT ;
run;
Data example.
Generally I don't let any of the graphics procedures to percentages because I almost always need at least one thing different than the graphic procedure can do.
So, precalculate the data , such as with Proc Freq creating a data set and use that data to plot. Then you have all the values you want.
You may have to move to a VBARPARM or similar to use such data.
My bad. I understood the results of proc freq were plotted. Yes, do a proc freq, and then plot what you need.
Hey!
I apologize if I was not clear. I did a proc freq and I wanted to display the row percent which I got through proc freq. I tried using PCTLEVEL = GROUP option in the proc sgplot statement and it worked for me. It displayed the percentages of the grouped variable and that's what I wanted.
Thank you!
I will try this. Thank you!
Are you using the output dataset from your PROC FREQ statement? Such as:
ODS OUTPUT Crosstabfreqs = WORK.bargraph;
PROC FREQ DATA=have;
TABLES var*var;
RUN;
Then, try this:
PROC SGPLOT DATA=work.bargraph; *from above ODS OUTPUT statement;
VBAR variable / RESPONSE = RowPercent DATALABEL
/*I'm assuming RowPercent is the variable name from your ODS OUTPUT dataset*/
Add the rest of your code here;
The main difference is the use of RESPONSE= instead of STAT=
Hope that helps!
Hey everyone!
I actually wanted to display the row percent which I obtained through proc freq. I figured it out. I actually used the PCTLEVEL = GROUP option in the proc sgplot statement. This worked! it displayed the row percentages of the grouped variable which is what I wanted to do. Thanks, everyone!
proc sgplot data = learn.data_main pctlevel = group;
vbar Place / response = check stat = percent
group = Ins groupdisplay = cluster datalabel ;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.