- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Have you tried this?
data_label= ROW_PERCENT (use the variable name)
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
My bad. I understood the results of proc freq were plotted. Yes, do a proc freq, and then plot what you need.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I will try this. Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;