BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Gick
Pyrite | Level 9

Gick_1-1683183809605.png

 

/* 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

1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Onyx | Level 15

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):

yabwon_0-1683186077977.png

 

 

 

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

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



View solution in original post

2 REPLIES 2
yabwon
Onyx | Level 15

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):

yabwon_0-1683186077977.png

 

 

 

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

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Rick_SAS
SAS Super FREQ

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: Call for Content

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Tips for filtering data sources in SAS Visual Analytics

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.

Discussion stats
  • 2 replies
  • 549 views
  • 1 like
  • 3 in conversation