Hello, I think it may be easier to first use Proc Frequency to calculate the percentages for the groups you are interesting, and then plot the graph. The code below plots the percentages of the outcomes for each location, but you will need to modify it so that it can be further stratified by drug. I think all you need to do extra is calculate the percentages by the drug stratification, and then modify Sanjay's code with some of the methods shown below. proc format; invalue $outcome "Yes" = 1 "No" = 0; value outcome 0 = "Yes" 1 = "No" other = ""; run; data sample; set data.sample; outcome1n = input(input(outcome1, $outcome.),best.); outcome2n = input(input(outcome2, $outcome.),best.); run; proc sort data = sample; by location; run; /* Obtaining Percentages for Outcome 1 by location */ proc freq data = sample; by location; tables outcome1n / out = freq_summ_1n; run; /* Obtaining Percentages for Outcome 2 by location*/ proc freq data = sample; by location; tables outcome2n / out = freq_summ_2n; run; /* Merging Percentages */ proc sql; create table final_data as select a.location, coalesce(a.outcome1n, b.outcome2n) as outcome, a.outcome1n as a_outcome, b.outcome2n as b_outcome, a.percent as a_pct, b.percent as b_pct from Freq_summ_1n as a full join Freq_summ_2n as b on a.location = b.location and a.outcome1n = b.outcome2n; quit; /* Plotting the data */ proc sgplot data = final_data; vbar location / response = a_pct group = outcome discreteoffset = -0.2 groupdisplay = stack barwidth = 0.2 name = "leg1"; /* Outcome 1 */ vbar location / response = b_pct group = outcome discreteoffset = 0.2 groupdisplay = stack barwidth = 0.2 name = "leg2"; /* Outcome 2 */ keylegend "leg1" "leg2"; format outcome outcome.; run;
... View more