<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Create a graph in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-a-graph/m-p/892726#M352615</link>
    <description>&lt;P&gt;Use PROC SGPLOT with the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/grstatproc/n0p7vdd69sgf3wn1479qxqxuryrt.htm" target="_self"&gt;VBAR statement&lt;/A&gt;, using the GROUPDISPLAY=STACK and STAT=PERCENT options.&lt;/P&gt;</description>
    <pubDate>Tue, 05 Sep 2023 12:41:48 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-09-05T12:41:48Z</dc:date>
    <item>
      <title>Create a graph</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-graph/m-p/892719#M352609</link>
      <description>&lt;P&gt;&lt;SPAN class="jCAhz ChMk0b"&gt;&lt;SPAN class="ryNqvb"&gt;Good morning,&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="jCAhz ChMk0b"&gt;&lt;SPAN class="ryNqvb"&gt;I have a database like this (see attached)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;data Mydata;&lt;BR /&gt;input Nom $ Sexe $ classe_age $ Sejour Annee;&lt;BR /&gt;datalines;&lt;BR /&gt;Jean Masculin 0-4ans 30 2021&lt;BR /&gt;Marie Feminin 5-14ans 2 2021&lt;BR /&gt;Pierre Masculin 15-24ans 4 2022&lt;BR /&gt;J Feminin 0-4ans 31 2022&lt;BR /&gt;M Feminin 5-14ans 21 2020&lt;BR /&gt;Pe Masculin 0-4ans 41 2021&lt;BR /&gt;Je Masculin 15-24ans 38 2022&lt;BR /&gt;Ma Masculin 0-4ans 15 2020&lt;BR /&gt;Pire Feminin 15-24ans 0 2020&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="jCAhz ChMk0b"&gt;&lt;SPAN class="ryNqvb"&gt;I would like to obtain this figure (see attached image).&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="jCAhz ChMk0b"&gt;&lt;SPAN class="ryNqvb"&gt;Can someone help me please.&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/87621iCA082490462D3520/image-size/medium?v=v2&amp;amp;px=400" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="jCAhz ChMk0b"&gt;&lt;SPAN class="ryNqvb"&gt;I thank you in advance.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="jCAhz ChMk0b"&gt;&lt;SPAN class="ryNqvb"&gt;Gick,&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Sep 2023 12:27:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-graph/m-p/892719#M352609</guid>
      <dc:creator>Gick</dc:creator>
      <dc:date>2023-09-05T12:27:36Z</dc:date>
    </item>
    <item>
      <title>Re: Create a graph</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-graph/m-p/892726#M352615</link>
      <description>&lt;P&gt;Use PROC SGPLOT with the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/grstatproc/n0p7vdd69sgf3wn1479qxqxuryrt.htm" target="_self"&gt;VBAR statement&lt;/A&gt;, using the GROUPDISPLAY=STACK and STAT=PERCENT options.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Sep 2023 12:41:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-graph/m-p/892726#M352615</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-09-05T12:41:48Z</dc:date>
    </item>
    <item>
      <title>Re: Create a graph</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-graph/m-p/892741#M352621</link>
      <description>&lt;P&gt;Proc SGPANEL will get you the graph, not pixel by pixel, but the content is right. The total need to be calculated and then combined with the original data. See code example below. The COLAXIS control the appearance of the "X" axis and the ROWAXIS controls the appearance of the "Y" axis. Give it a try.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Mydata;
  input Nom $ Sexe $ classe_age $ Sejour Annee;
  datalines;
Jean Masculin 0-4ans 30 2021
Marie Feminin 5-14ans 2 2021
Pierre Masculin 15-24ans 4 2022
J Feminin 0-4ans 31 2022
M Feminin 5-14ans 21 2020
Pe Masculin 0-4ans 41 2021
Je Masculin 15-24ans 38 2022
Ma Masculin 0-4ans 15 2020
Pire Feminin 15-24ans 0 2020
;
/*
 * calculate total
 */
proc sql;
create table total as
select
  annee
  , "total" as sexe
  , classe_age
  , sum(sejour) as sejour
from
  mydata
group by
  annee
  , sexe
  , classe_age
;
quit;

/*
 * combine
 */
data have;
  set mydata total;
run;

proc sgpanel data=have pctlevel=group;
  panelby annee / layout=columnlattice colheaderpos=bottom;
  vbar sexe / group=classe_age stat=percent name="vbar";
  keylegend "vbar" / position=right across=1 noborder autoitemsize;
  colaxis display=(nolabel) valuesrotate=vertical;
  rowaxis display=(nolabel) grid gridattrs=(color=grey);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Sep 2023 13:52:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-graph/m-p/892741#M352621</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2023-09-05T13:52:10Z</dc:date>
    </item>
    <item>
      <title>Re: Create a graph</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-graph/m-p/892742#M352622</link>
      <description>&lt;P&gt;&lt;SPAN class="jCAhz ChMk0b"&gt;&lt;SPAN class="ryNqvb"&gt;Thank you so much.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="jCAhz ChMk0b"&gt;&lt;SPAN class="ryNqvb"&gt;that works.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Sep 2023 13:55:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-graph/m-p/892742#M352622</guid>
      <dc:creator>Gick</dc:creator>
      <dc:date>2023-09-05T13:55:46Z</dc:date>
    </item>
    <item>
      <title>Re: Create a graph</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-graph/m-p/892748#M352625</link>
      <description>On the other hand, I just noticed that you used the Stay variable for the total. While the total must correspond to the number of times an age group is used.&lt;BR /&gt;&lt;BR /&gt;Thanks for your help</description>
      <pubDate>Tue, 05 Sep 2023 14:13:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-graph/m-p/892748#M352625</guid>
      <dc:creator>Gick</dc:creator>
      <dc:date>2023-09-05T14:13:24Z</dc:date>
    </item>
    <item>
      <title>Re: Create a graph</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-graph/m-p/892837#M352667</link>
      <description>data Mydata;&lt;BR /&gt;  input Nom $ Sexe $ classe_age $ Annee;&lt;BR /&gt;  datalines;&lt;BR /&gt;Jean Masculin 0-4ans 2021&lt;BR /&gt;Marie Feminin 5-14ans 2021&lt;BR /&gt;Pierre Masculin 15-24ans 2022&lt;BR /&gt;J Feminin 0-4ans 2022&lt;BR /&gt;M Feminin 5-14ans 2020&lt;BR /&gt;Pe Masculin 0-4ans 2021&lt;BR /&gt;Je Masculin 15-24ans 2022&lt;BR /&gt;Ma Masculin 0-4ans 2020&lt;BR /&gt;Pire Feminin 15-24ans 2020&lt;BR /&gt;; run; can someone help me make this graph with this data please&lt;BR /&gt;&lt;BR /&gt;Thanks in advance.&lt;BR /&gt;&lt;BR /&gt;Gick</description>
      <pubDate>Wed, 06 Sep 2023 04:57:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-graph/m-p/892837#M352667</guid>
      <dc:creator>Gick</dc:creator>
      <dc:date>2023-09-06T04:57:51Z</dc:date>
    </item>
    <item>
      <title>Re: Create a graph</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-graph/m-p/892853#M352680</link>
      <description>&lt;P&gt;The VBAR statement calculated the frequencies, number of times a given agegroup occurs within the sexe and annee by default.&lt;/P&gt;
&lt;P&gt;You can just calculate the total differently. See below the changed code. I have added a variable N to the input data with a value of 1. For the total calculation I use the count(*) to count the number of rows in a given group. This new variable N is now used in the VBAR statement as the response variable. It should now give the proper values back. I have also added some options to the PANELBY&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Mydata;
  input Nom $ Sexe $ classe_age $ Sejour Annee;
  n = 1;
  datalines;
Jean Masculin 0-4ans 30 2021
Marie Feminin 5-14ans 2 2021
Pierre Masculin 15-24ans 4 2022
J Feminin 0-4ans 31 2022
M Feminin 5-14ans 21 2020
Pe Masculin 0-4ans 41 2021
Je Masculin 15-24ans 38 2022
Ma Masculin 0-4ans 15 2020
Pire Feminin 15-24ans 0 2020
;
/*
 * calculate total
 */
proc sql;
create table total as
select
  annee
  , "total" as sexe
  , classe_age
  , sum(sejour) as sejour
  , count(*) as n
from
  mydata
group by
  annee
  , sexe
  , classe_age
;
quit;

/*
 * combine
 */
data have;
  set mydata total;
run;

proc sgpanel data=have pctlevel=group;
  panelby annee / layout=columnlattice colheaderpos=bottom novarname noheaderborder;
  vbar sexe / group=classe_age response=n stat=percent name="vbar";
  keylegend "vbar" / position=right across=1 noborder autoitemsize;
  colaxis display=(nolabel) valuesrotate=vertical;
  rowaxis display=(nolabel) grid gridattrs=(color=grey);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2023 07:30:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-graph/m-p/892853#M352680</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2023-09-06T07:30:25Z</dc:date>
    </item>
    <item>
      <title>Re: Create a graph</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-graph/m-p/892909#M352697</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*
You want this ?
*/

data Mydata;
input Nom $ Sexe $ classe_age $ Annee;
datalines;
Jean Masculin 0-4ans 2021
Marie Feminin 5-14ans 2021
Pierre Masculin 15-24ans 2022
J Feminin 0-4ans 2022
M Feminin 5-14ans 2020
Pe Masculin 0-4ans 2021
Je Masculin 15-24ans 2022
Ma Masculin 0-4ans 2020
Pire Feminin 15-24ans 2020
; 
/*
 * calculate total
 */
proc sql;
create table total as
select annee,sexe,classe_age,count(*) as sejour from mydata
  group by annee,sexe,classe_age
union
select annee,"total",classe_age,count(*) from mydata
  group by annee,classe_age
;
quit;

proc sgpanel data=total pctlevel=group;
  panelby annee / layout=columnlattice colheaderpos=bottom;
  vbar sexe / group=classe_age response=sejour stat=percent name="vbar";
  keylegend "vbar" / position=right across=1  noborder autoitemsize;
  colaxis display=(nolabel) valuesrotate=vertical;
  rowaxis display=(nolabel) grid gridattrs=(color=grey);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1694001828119.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/87663i26AC848EAD320768/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1694001828119.png" alt="Ksharp_0-1694001828119.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2023 12:03:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-graph/m-p/892909#M352697</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-09-06T12:03:19Z</dc:date>
    </item>
  </channel>
</rss>

