<?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: How do I create a line graph showing proportion, by age, over time using PROC SGPLOT? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-line-graph-showing-proportion-by-age-over-time/m-p/805398#M317264</link>
    <description>&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;Can you accomplish the same thing using PROC FREQ instead of PROC SUMMARY?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 31 Mar 2022 21:46:27 GMT</pubDate>
    <dc:creator>_maldini_</dc:creator>
    <dc:date>2022-03-31T21:46:27Z</dc:date>
    <item>
      <title>How do I create a line graph showing proportion, by age, over time using PROC SGPLOT?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-line-graph-showing-proportion-by-age-over-time/m-p/805381#M317255</link>
      <description>&lt;P&gt;I'd like to create a line graph showing the proportion of respondents answering "Yes" to past month tobacco use, by age category, over time. Basically I am trying to create a graph like this one:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="IMG_7992.jpg" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70012i58D224D4F6FAF2AD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="IMG_7992.jpg" alt="IMG_7992.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2019/3167-2019.pdf" target="_self"&gt;These instructions&lt;/A&gt; are helpful, but I'm not sure how to manipulate the data before running the PROC SGPLOT.&lt;/P&gt;
&lt;P&gt;When I run this syntax using the data as is...&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
PROC SGPLOT DATA = input;
   SERIES X = year Y = past_month_use / group=age_cat;
   SERIES X = year Y = past_month_use / group=age_cat;
   SERIES X = year Y = past_month_use / group=age_cat;
RUN; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I get this:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2022-03-31 at 11.46.17 AM.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70013i7007F5D01A1B8279/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screen Shot 2022-03-31 at 11.46.17 AM.png" alt="Screen Shot 2022-03-31 at 11.46.17 AM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do I need to manipulate these data so that I can produce the desired outcome?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Sample data below:&lt;/STRONG&gt;&lt;BR /&gt;4 vars:&lt;BR /&gt;id (1-20 respondents)&lt;BR /&gt;age_cat (1,2,3)&lt;BR /&gt;past_month_use (0=no, 1=yes)&lt;BR /&gt;year (2018-2020)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;id age_cat past_month_use year&lt;/DIV&gt;
&lt;DIV&gt;1 1 1 2018&lt;/DIV&gt;
&lt;DIV&gt;1 1 1 2019&lt;/DIV&gt;
&lt;DIV&gt;1 1 1 2020&lt;/DIV&gt;
&lt;DIV&gt;1 2 0 2021&lt;/DIV&gt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;
&lt;DIV&gt;18 2 1 2018&lt;/DIV&gt;
&lt;DIV&gt;18 2 1 2019&lt;/DIV&gt;
&lt;DIV&gt;18 2 1 2020&lt;/DIV&gt;
&lt;DIV&gt;18 2 1 2021&lt;/DIV&gt;
&lt;DIV&gt;19 3 1 2018&lt;/DIV&gt;
&lt;DIV&gt;19 3 1 2019&lt;/DIV&gt;
&lt;DIV&gt;19 3 1 2020&lt;/DIV&gt;
&lt;DIV&gt;19 3 1 2021&lt;/DIV&gt;
&lt;DIV&gt;20 1 1 2018&lt;/DIV&gt;
&lt;DIV&gt;20 2 1 2019&lt;/DIV&gt;
&lt;DIV&gt;20 2 1 2020&lt;/DIV&gt;
&lt;DIV&gt;20 2 1 2021&lt;/DIV&gt;</description>
      <pubDate>Thu, 31 Mar 2022 18:51:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-line-graph-showing-proportion-by-age-over-time/m-p/805381#M317255</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2022-03-31T18:51:45Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a line graph showing proportion, by age, over time using PROC SGPLOT?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-line-graph-showing-proportion-by-age-over-time/m-p/805393#M317260</link>
      <description>&lt;P&gt;Do you mean something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id age_cat past_month_use year;
cards;
1 1 1 2018
1 1 1 2019
1 1 1 2020
1 2 0 2021
2 2 0 2018
2 2 0 2019
2 2 1 2020
2 2 1 2021
3 3 1 2018
3 3 1 2019
3 3 1 2020
3 3 1 2021
4 2 1 2018
4 3 1 2019
4 3 1 2020
4 3 1 2021
5 1 0 2018
5 1 0 2019
5 1 0 2020
5 1 0 2021
6 3 0 2018
6 3 1 2019
6 3 0 2020
6 3 1 2021
7 2 1 2018
7 2 1 2019
7 2 1 2020
7 2 1 2021
8 2 0 2018
8 2 1 2019
8 3 0 2020
8 3 1 2021
9 3 1 2018
9 3 1 2019
9 3 1 2020
9 3 1 2021
10 1 1 2018
10 1 0 2019
10 1 0 2020
10 1 0 2021
11 2 0 2018
11 2 0 2019
11 2 1 2020
11 2 1 2021
12 1 1 2018
12 1 0 2019
12 1 1 2020
12 2 1 2021
13 3 1 2018
13 3 1 2019
13 3 1 2020
13 3 1 2021
14 2 1 2018
14 2 1 2019
14 2 0 2020
14 3 0 2021
15 1 0 2018
15 1 0 2019
15 1 1 2020
15 1 1 2021
16 2 1 2018
16 2 0 2019
16 2 0 2020
16 2 0 2021
17 2 0 2018
17 3 1 2019
17 3 1 2020
17 3 1 2021
18 2 1 2018
18 2 1 2019
18 2 1 2020
18 2 1 2021
19 3 1 2018
19 3 1 2019
19 3 1 2020
19 3 1 2021
20 1 1 2018
20 2 1 2019
20 2 1 2020
20 2 1 2021
;
run;

proc sort data = have;
  by year age_cat past_month_use id;
run;

data want;
  set have;
  by year age_cat;
  if first.age_cat then
    do;
      d = 0;
      n = 0;
    end;

  d + past_month_use;
  n + 1;

  if last.age_cat then
    do;
      prop = divide(d,n);
      if prop then output;
      format prop percent10.2;
    end;
run;

proc sgplot data = want;
  series x = year y = prop / group=age_cat;
  xaxis integer;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;?&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2022 20:16:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-line-graph-showing-proportion-by-age-over-time/m-p/805393#M317260</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2022-03-31T20:16:45Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a line graph showing proportion, by age, over time using PROC SGPLOT?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-line-graph-showing-proportion-by-age-over-time/m-p/805394#M317261</link>
      <description>&lt;P&gt;You need to summarize the data to create the proportion.&lt;/P&gt;
&lt;P&gt;Using a 1/0 coded value when you use the mean you get the percentage (proportion) of 1 values. I used proc summary, other methods are possible, to create data set with the summary and the other values.&lt;/P&gt;
&lt;P&gt;The Xaxis and Yaxis statements to make the X values "nicer" and to force 0 into the graph for the Y value axis.&lt;/P&gt;
&lt;P&gt;The format is very optional but sets a nice appearance. Labels on your variables would get nicer axis labels.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
  input id age_cat past_month_use year;
datalines;
1 1 1 2018
1 1 1 2019
1 1 1 2020
1 2 0 2021
2 2 0 2018
2 2 0 2019
2 2 1 2020
2 2 1 2021
3 3 1 2018
3 3 1 2019
3 3 1 2020
3 3 1 2021
4 2 1 2018
4 3 1 2019
4 3 1 2020
4 3 1 2021
5 1 0 2018
5 1 0 2019
5 1 0 2020
5 1 0 2021
6 3 0 2018
6 3 1 2019
6 3 0 2020
6 3 1 2021
7 2 1 2018
7 2 1 2019
7 2 1 2020
7 2 1 2021
8 2 0 2018
8 2 1 2019
8 3 0 2020
8 3 1 2021
9 3 1 2018
9 3 1 2019
9 3 1 2020
9 3 1 2021
10 1 1 2018
10 1 0 2019
10 1 0 2020
10 1 0 2021
11 2 0 2018
11 2 0 2019
11 2 1 2020
11 2 1 2021
12 1 1 2018
12 1 0 2019
12 1 1 2020
12 2 1 2021
13 3 1 2018
13 3 1 2019
13 3 1 2020
13 3 1 2021
14 2 1 2018
14 2 1 2019
14 2 0 2020
14 3 0 2021
15 1 0 2018
15 1 0 2019
15 1 1 2020
15 1 1 2021
16 2 1 2018
16 2 0 2019
16 2 0 2020
16 2 0 2021
17 2 0 2018
17 3 1 2019
17 3 1 2020
17 3 1 2021
18 2 1 2018
18 2 1 2019
18 2 1 2020
18 2 1 2021
19 3 1 2018
19 3 1 2019
19 3 1 2020
19 3 1 2021
20 1 1 2018
20 2 1 2019
20 2 1 2020
20 2 1 2021
;

proc summary data=have nway;
   class age_cat year;
   var past_month_use ;
   output out=summary mean=;
run;

proc sgplot data=summary;
   series x=year y=past_month_use/ group=age_cat;
   xaxis values=(2018 to 2021 by 1) ;
   yaxis values=(0 to 1 by .1);
   format past_month_use percent6.;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Mar 2022 20:23:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-line-graph-showing-proportion-by-age-over-time/m-p/805394#M317261</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-03-31T20:23:51Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a line graph showing proportion, by age, over time using PROC SGPLOT?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-line-graph-showing-proportion-by-age-over-time/m-p/805398#M317264</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;Can you accomplish the same thing using PROC FREQ instead of PROC SUMMARY?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2022 21:46:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-line-graph-showing-proportion-by-age-over-time/m-p/805398#M317264</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2022-03-31T21:46:27Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a line graph showing proportion, by age, over time using PROC SGPLOT?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-line-graph-showing-proportion-by-age-over-time/m-p/805402#M317265</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/36911"&gt;@_maldini_&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;Can you accomplish the same thing using PROC FREQ instead of PROC SUMMARY?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Suggestion is always "try and see".&lt;/P&gt;
&lt;P&gt;The main thing with proc freq is it COUNTS all formatted values. So you would end up with counts/percents of 0 as well as 1. Also Proc Freq shifts percentages calculated by *100 so the Y axis values change.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc freq data=have noprint;
  tables age_cat*year*past_month_use / outpct out=freqout;

run;

proc sgplot data=freqout;
   where past_month_use=1;
   series x=year y=pct_row/ group=age_cat;
   xaxis values=(2018 to 2021 by 1) ;
   yaxis values=(0 to 100 by 10);
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Mar 2022 22:20:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-line-graph-showing-proportion-by-age-over-time/m-p/805402#M317265</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-03-31T22:20:33Z</dc:date>
    </item>
  </channel>
</rss>

