I am using this code to get percent of bars within group (data_column_C), but what I am getting is percent within data_column_A category.
Basically I want the percents to sum up to 100% for data_column_C and have individual bar by data_column_A.
proc sgplot data=data_table pctlevel=group;
vline data_column_A /response=data_column_B stat=mean limitstat=clm markers group=data_column_C lineattrs=(thickness=2);
vbar data_column_A / response=data_column_B y2axis transparency=0.75 group=data_column_C groupdisplay=cluster stat=percent;
run;
If I'm interpreting your request correctly, you really want to set PCTLEVEL=GRAPH (which is the default). Give that a try and see if the numbers are what you expect.
Thanks!
Dan
Can you post a picture of what you're getting without the BY statement?
What I want is that the blue bars sum up to 100% and the pink bars also sum up to 100%. The variable name differentiating them is DATA_COLUMN_C in my code above. 0-14 are DATA_COLUMN_A values and DATA_COLUMN_B is the response variable.
The way you can do this is to transpose the data such that the values in DATA_COLUMN_B are put into DATA_COLUMN_B1 and DATA_COLUMN_B2, depending on the value in DATA_COLUMN_C. Then, your plot becomes 2 vbar sttements with stat=mean and 2 vline statements with stat=percent. The PCTLEVEL option will not be required.
Hope this helps!
Dan
i think this is a much needed function in sgplot.
my work-around is to use proc freq to export the percentages and then use sgplot. like
proc freq data=xxx noprint;table a*b/out=XXXX outpct;run;
proc sgplot data=XXXX;vbar b /response=pct_row group=a groupdisplay=cluster;run;
These work around codes work for me. Now, I'm having the percentage display on the bars (datalabel). Is it possible to limit the decimal places to one only. It's displaying 3 and that's too much.
Thanks.
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 16. 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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: