@yabwon since am still not getting the positioning let me post how my data really looks like maybe you can help
data have;
infile datalines;
input period $10. drug $15. visit dosis 2.;
datalines;
2000-2005 Cefalexin 1 12
2000-2005 Calcipotriol 1 16
2000-2005 Folic acid 1 26
2000-2005 Piriton 1 3
2000-2005 Fentanyl 1 36 2000-2005 Folic acid 1 26
2000-2005 Co-beneldopa 1 35
2000-2005 Folic acid 1 26
2000-2005 Cefalexin 1 11
2000-2005 Fentanyl 1 35
2006-2011 Allopurinol 1 33
2006-2011 Folic acid 1 27
2006-2011 Cefalexin 1 11
2006-2011 Allopurinol 1 33
2006-2011 Cefalexin 1 11
2006-2011 Folic acid 1 26
2006-2011 Piriton 1 3
2006-2011 Folic acid 1 27
2006-2011 Allopurinol 1 33
2006-2011 Piriton 1 3
2006-2011 Cefalexin 1 11
2011-2022 Piriton 1 3
2011-2022 Cefalexin 1 11
2011-2022 Cefalexin 1 12
2011-2022 Cefalexin 1 11
2011-2022 Cefalexin 1 11
2011-2022 Baclofen 1 35
2011-2022 Diclofenac 1 22
2011-2022 Diclofenac 1 22
2011-2022 Co-beneldopa 1 35
2011-2022 Co-beneldopa 1 3
2011-2022 Other Piriton 1 22
2000-2005 Co-beneldopa 2 3
2000-2005 Folic acid 2 15
2000-2005 Cefalexin 2 14
2000-2005 Fentanyl 2 11
2000-2005 Allopurinol 2 3
2000-2005 Folic acid 2 3
2000-2005 Cefalexin 2 5
2000-2005 Allopurinol 2 15
2000-2005 Cefalexin 2 35
2006-2011 Folic acid 2 16
2006-2011 Piriton 2 22
2006-2011 Folic acid 2 38
2006-2011 Allopurinol 2 11
2006-2011 Piriton 2 7
2006-2011 Cefalexin 2 11
2006-2011 Piriton 2 11
2006-2011 Cefalexin 2 15
2006-2011 Cefalexin 2 17
2006-2011 Cefalexin 2 11
2011-2022 Cefalexin 2 33
2011-2022 Baclofen 2 77
2011-2022 Diclofenac 2 25
2011-2022 Acrivastine 2 12
2011-2022 Acrivastine 2 8
2011-2022 Acrivastine 2 15
2011-2022 Acrivastine 2 20
2011-2022 Acrivastine 2 6
2011-2022 Acrivastine 2 20
2011-2022 Acrivastine 2 33
2011-2022 Other Piriton 2 14
2000-2005 Cefalexin 3 14
2000-2005 Calcipotriol 3 18
2000-2005 Folic acid 3 16
2000-2005 Piriton 3 15
2000-2005 Fentanyl 3 19
2000-2005 Folic acid 3 20
2000-2005 Co-beneldopa 3 25
2000-2005 Folic acid 3 52
2000-2005 Cefalexin 3 25
2000-2005 Fentanyl 3 16
2006-2011 Allopurinol 3 8
2006-2011 Folic acid 3 2
2006-2011 Cefalexin 3 55
2006-2011 Allopurinol 3 70
2006-2011 Cefalexin 3 18
2006-2011 Folic acid 3 1
2006-2011 Piriton 3 20
2006-2011 Folic acid 3 11
2006-2011 Allopurinol 3 14
2006-2011 Piriton 3 7
2006-2011 Cefalexin 3 33
2011-2022 Piriton 3 20
2011-2022 Cefalexin 3 15
2011-2022 Cefalexin 3 12
2011-2022 Cefalexin 3 77
2011-2022 Cefalexin 3 6
2011-2022 Acrivastine 3 44
2011-2022 Acrivastine 3 7
2011-2022 Acrivastine 3 25
2011-2022 Acrivastine 3 11
2011-2022 Acrivastine 3 9
2011-2022 Other Piriton 3 8
;
run;
proc sql;
create table have2 as select period, drug, visit, sum(dosis) as SumDosis from have group by period, drug, visit;
create table sumtotal as select period,visit, sum(SumDosis) as totals from have2 group by period, visit;
create table have3 as select a.*, b.totals, SumDosis/totals as percentage format percent8.2 from have2 as
a, sumtotal as b where a.visit=b.visit and a.period=b.period;
quit;
data have4;
set have3;
length N_percentage $15 ;
N_Percentage=catx(" ", SumDosis, "(", put(percentage, percent8.2), ")");
keep period drug visit SumDosis N_percentage;
run;
proc sort data have4;
by period visit drug;
run;
proc sgpanel data = have4;
styleattrs datacolors=(lightgreen lightred lightblue);
panelby period /columns=3 novarname noborder;
vbarparm category=visit response=SumDosis / group=drug grouporder=data datalabel seglabel groupdisplay=stack;
*text x=year y=pos text=vallabel / group=group TEXTATTRS=(Color=black Family="Arial" Size=8 Weight=bold)
;
run;
This is how it looks like when I apply your code:
data have5;
tot = 0;
do _N_ = 1 to _N_;
set have4;
pos = tot + 0.5*SumDosis;
tot + SumDosis;
glabel = N_percentage;
output;
end;
run;
proc sgpanel data = have5;
styleattrs datacolors=(lightgreen lightred lightblue);
panelby period /columns=3 novarname noborder;
vbarparm category=visit response=SumDosis / group=drug grouporder=data datalabel groupdisplay=stack;
text x=visit y=pos text=glabel / group=drug TEXTATTRS=(Color=black Family="Arial" Size=8 Weight=bold)
;
run;
... View more