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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Gayatrikunchay
Obsidian | Level 7

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;

 

View solution in original post

8 REPLIES 8
ChrisNZ
Tourmaline | Level 20

Have you tried this?

data_label= ROW_PERCENT  (use the variable name)
ChrisNZ
Tourmaline | Level 20

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;

 

ballardw
Super User

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.

ChrisNZ
Tourmaline | Level 20

My bad. I understood the results of proc freq were plotted. Yes, do a proc freq, and then plot what you need.

Gayatrikunchay
Obsidian | Level 7

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! 

 

Gayatrikunchay
Obsidian | Level 7

I will try this. Thank you!

strong_s
Fluorite | Level 6

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!  

Gayatrikunchay
Obsidian | Level 7

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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 8 replies
  • 6401 views
  • 6 likes
  • 4 in conversation