/* Creating the table */
data piechart;
input secteur $ Annee_2017 Annee_2018 Annee_2019;
datalines;
A 35 12 3
B 10 2 0
C 22 22 13
D 40 67 7
;
run;
I wish to have this graph (in image above).
Which procedure allows to have it.
Best regards,
Gick
for start use this:
data piechart; input secteur $ Annee_2017 Annee_2018 Annee_2019; datalines; A 35 12 3 B 10 2 0 C 22 22 13 D 40 67 7 ; run; proc transpose data=piechart out=temp; by secteur; var Annee_2017 Annee_2018 Annee_2019; run; data temp; set temp; period = _name_; drop _name_; run; proc sort data=temp; by period secteur; run; proc freq data=temp noprint; by period; table secteur / out=temp1; weight col1; run; PROC SGPLOT DATA=temp1; VBAR period / GROUP=secteur RESPONSE=percent SEGLABEL SEGLABELFITPOLICY= NONE ; RUN;
you should get (even in M3):
then read about:
1) proc SGPLOT VBAR: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatproc/n0p7vdd69sgf3wn1479qxqxuryrt.htm
2) some general overview: https://www.lexjansen.com/wuss/2008/how/how05.pdf
3) blog posts about plotting with SGPLOT:
a) https://blogs.sas.com/content/tag/proc-sgplot/
b) https://blogs.sas.com/content/tag/sgplot-procedure/
Bart
for start use this:
data piechart; input secteur $ Annee_2017 Annee_2018 Annee_2019; datalines; A 35 12 3 B 10 2 0 C 22 22 13 D 40 67 7 ; run; proc transpose data=piechart out=temp; by secteur; var Annee_2017 Annee_2018 Annee_2019; run; data temp; set temp; period = _name_; drop _name_; run; proc sort data=temp; by period secteur; run; proc freq data=temp noprint; by period; table secteur / out=temp1; weight col1; run; PROC SGPLOT DATA=temp1; VBAR period / GROUP=secteur RESPONSE=percent SEGLABEL SEGLABELFITPOLICY= NONE ; RUN;
you should get (even in M3):
then read about:
1) proc SGPLOT VBAR: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatproc/n0p7vdd69sgf3wn1479qxqxuryrt.htm
2) some general overview: https://www.lexjansen.com/wuss/2008/how/how05.pdf
3) blog posts about plotting with SGPLOT:
a) https://blogs.sas.com/content/tag/proc-sgplot/
b) https://blogs.sas.com/content/tag/sgplot-procedure/
Bart
Read "Construct a stacked bar chart in SAS where each bar equals 100%"
If you don't need the labels for each segment, PROC FREQ can create the entire plot. FOr more control, use PROC SGPLOT, as shown:
proc transpose data=piechart Name=Period out=temp(rename=(col1=Count));
by secteur;
var Annee_2017 Annee_2018 Annee_2019;
run;
/* stacked, but no bar labels */
proc freq data=temp;
tables Period*secteur / plots=freqplot(twoway=stacked scale=grouppct);
weight Count;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
See how to use one filter for multiple data sources by mapping your data from SAS’ Alexandria McCall.
Find more tutorials on the SAS Users YouTube channel.