<?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 to create a line graph in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-line-graph/m-p/709801#M218359</link>
    <description>sorry yes i meant "cumulative count of subjects" would the code above work? thank you</description>
    <pubDate>Thu, 07 Jan 2021 04:27:10 GMT</pubDate>
    <dc:creator>HitmonTran</dc:creator>
    <dc:date>2021-01-07T04:27:10Z</dc:date>
    <item>
      <title>how to create a line graph</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-line-graph/m-p/709793#M218354</link>
      <description>&lt;P&gt;Hi new to SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having difficulty deriving the:&lt;/P&gt;&lt;P&gt;1. y-axis (&lt;SPAN&gt;cumulative count of subjects&lt;/SPAN&gt;) and&lt;/P&gt;&lt;P&gt;2.creating x-axis(months)&amp;nbsp;&lt;/P&gt;&lt;P&gt;3.&amp;nbsp; outputting it onto a .rtf file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the y-axis, i am currently using usubjid but it's outputting usubjid # and not # of subject. I think i have to get the cumulative counts and use it as my y-axis but not sure how to do so.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;want:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HitmonTran_0-1609991704815.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/53270i78F92DAF155F08D3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HitmonTran_0-1609991704815.png" alt="HitmonTran_0-1609991704815.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;my data:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;usubjid   enrldt
bob        01-01-2021
alex       01-01-2021
sara       02-02-2021
chris      03-02-2021
patty      04-03-2021&lt;BR /&gt;jon        05-01-2021
dav        06-02-2021
justin     07-02-2021
cara       08-03-2021&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=adam.adsl out=adsl(keep=usubjid  enrlfl enrldt);
by usubjid;
where enrlfl='Y';
run;

proc sgplot data=adsl noautolegend;
reg x=enrldt y=usubjid / lineattrs=(pattern=shortdash);
series x=enrldt y=usubjid;
yaxis grid;
run;



&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jan 2021 04:37:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-line-graph/m-p/709793#M218354</guid>
      <dc:creator>HitmonTran</dc:creator>
      <dc:date>2021-01-07T04:37:27Z</dc:date>
    </item>
    <item>
      <title>Re: how to create a line graph</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-line-graph/m-p/709799#M218357</link>
      <description>&lt;P&gt;Do you want the yaxis to be "count of subjects per date" or some sort of "cumulative count of subjects" as the text in that image shows?&lt;/P&gt;
&lt;P&gt;If the cumulative then a regression line doesn't really make much sense because regression should mean that the result for each date is independent of other dates, which would not be the case in cumulative totals.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to do something to create the count per date to do series, scatter and similar graphs. The bar graphs, like VBAR or HBAR can to a count per date but aren't going to be series.&lt;/P&gt;
&lt;PRE&gt;proc summary data = adam.adsl nway;
   class enrlfl enrldt;
   output out=work.toplot (drop=_type_);
run;

/* toplot will have enrlfl and enrldt plus
a variable _freq_ that counts how many records
for each combination of enrlfl and enrldt
*/

Proc sgplot data=work.toplot;
   reg x=enrldt y=_freq_ / lineattrs=(pattern=shortdash);
   series x=enrldt y=_freq_;
   yaxis grid;
   label _freq_='Subject count';
run;   &lt;/PRE&gt;
&lt;P&gt;You do not show very much "data" so I can't tell if you actually want count be date or per month as per your example image. If you need per calendar month (or other typical period) you can use a format to create summaries by the formatted value of Enrldt if that variable is an actual date value. A format of MONYY7. applied in proc summary to a date variable creates groups like MAY2020.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jan 2021 04:24:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-line-graph/m-p/709799#M218357</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-01-07T04:24:12Z</dc:date>
    </item>
    <item>
      <title>Re: how to create a line graph</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-line-graph/m-p/709801#M218359</link>
      <description>sorry yes i meant "cumulative count of subjects" would the code above work? thank you</description>
      <pubDate>Thu, 07 Jan 2021 04:27:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-line-graph/m-p/709801#M218359</guid>
      <dc:creator>HitmonTran</dc:creator>
      <dc:date>2021-01-07T04:27:10Z</dc:date>
    </item>
    <item>
      <title>Re: how to create a line graph</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-line-graph/m-p/709803#M218361</link>
      <description>&lt;P&gt;please try the below approach&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sort data=adam.adsl out=adsl(keep=usubjid enrlfl enrldt);
by enrldt;
where enrlfl='Y';
run;

data adsl;
set adsl;
retain count;
by enrldt;
if first.enrldt then count=1;
else count+1;
run;

ods rtf file='~path\line.rtf';
proc sgplot data=adsl noautolegend;
*reg x=enrldt y=usubjid / lineattrs=(pattern=shortdash);
series x=enrldt y=count;
yaxis grid;
run;
ods rtf close;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Jan 2021 04:36:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-line-graph/m-p/709803#M218361</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2021-01-07T04:36:14Z</dc:date>
    </item>
    <item>
      <title>Re: how to create a line graph</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-line-graph/m-p/709804#M218362</link>
      <description>i updated my post to update the x-axis as well (create months).</description>
      <pubDate>Thu, 07 Jan 2021 04:42:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-line-graph/m-p/709804#M218362</guid>
      <dc:creator>HitmonTran</dc:creator>
      <dc:date>2021-01-07T04:42:07Z</dc:date>
    </item>
    <item>
      <title>Re: how to create a line graph</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-line-graph/m-p/709808#M218364</link>
      <description>&lt;P&gt;please try the below code&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sort data=adam.adsl out=adsl(keep=usubjid enrlfl enrldt);
by enrldt;
where enrlfl='Y';
run;

proc format;
value mon
1='Jan'
2='Feb'
3='Mar'
4='Apr'
5='May'
6='Jun'
7='Jul'
8='Aug'
9='Sep'
10='Oct'
11='Nov'
12='Dec';
run;

data adsl;
set adsl;
month=month(enrldt);
run;

proc sort data=adsl;
by month;
run;

data adsl;
set adsl;
retain count;
by month;
if first.month then count=1;
else count+1;

run;

ods rtf file='F:\abgen\line.rtf';
proc sgplot data=adsl noautolegend;
*reg x=enrldt y=usubjid / lineattrs=(pattern=shortdash);
series x=month y=count;
yaxis grid;
XAXIS TYPE = DISCRETE GRID; 
format month mon.;
run;
ods rtf close;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Jan 2021 05:05:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-line-graph/m-p/709808#M218364</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2021-01-07T05:05:48Z</dc:date>
    </item>
    <item>
      <title>Re: how to create a line graph</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-line-graph/m-p/709814#M218368</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/111564"&gt;@HitmonTran&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;sorry yes i meant "cumulative count of subjects" would the code above work? thank you&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No because there is no accumulation. You would need to do an additional step to do so such as:&lt;/P&gt;
&lt;PRE&gt;proc summary data = adam.adsl nway;
   class enrlfl enrldt;
   format enrldt monyy7.;
   output out=work.summary (drop=_type_);
run;

/* accumlate count*/

data work.toplot;
   set work.summary;
   by enrlfl enrldt;
   retain count;
   if first.enrlfl then count=_freq_;
   else count+_freq_;
   enrldt = intnx('month',enrldt,0,'B');
end;

Proc sgplot data=work.toplot;
   where enrlfl="whatever";
   reg x=enrldt y=count / lineattrs=(pattern=shortdash);
   series x=enrldt y=count;
   yaxis grid;
   label count='Cumulative count';
run;   &lt;/PRE&gt;
&lt;P&gt;The INTNX function in the data step adjusts actual dates so they all represent the first of the month which might make your graph a bit closer to your expectations.&lt;/P&gt;
&lt;P&gt;Here you see why I used the Enrlfl variable in the summary. You can select just to plot for that data.&lt;/P&gt;
&lt;P&gt;Or you could try&lt;/P&gt;
&lt;PRE&gt;Proc sgplot data=work.toplot;
  
   reg x=enrldt y=count / lineattrs=(pattern=shortdash);
   series x=enrldt y=count / group=enrlfl;
   yaxis grid;
   label count='Cumulative count';
run;  &lt;/PRE&gt;
&lt;P&gt;to superimpose the different enrlfl values on one graph.&lt;/P&gt;
&lt;P&gt;Or use Enrlfl on a BY statement to create one graph per level.&lt;/P&gt;
&lt;P&gt;Or use Proc SGpanel with Enrlfl as the Panelby variable which can make panels of graphs, one for each level.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jan 2021 05:43:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-line-graph/m-p/709814#M218368</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-01-07T05:43:01Z</dc:date>
    </item>
    <item>
      <title>Re: how to create a line graph</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-line-graph/m-p/709976#M218459</link>
      <description>Thanks! it worked but how do I remove the y-axis label without removed the gridlines and also remove the legend?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Proc sgplot data=work.toplot;&lt;BR /&gt;where enrlfl='Y';&lt;BR /&gt;reg x=enrldt y=count / lineattrs=(pattern=shortdash);&lt;BR /&gt;series x=enrldt y=count;&lt;BR /&gt;yaxis grid;&lt;BR /&gt;XAXIS DISPLAY=(NOLABEL);&lt;BR /&gt;YAXIS DISPLAY=(NOLABEL);&lt;BR /&gt;label count='Cumulative count';&lt;BR /&gt;run;</description>
      <pubDate>Thu, 07 Jan 2021 17:54:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-line-graph/m-p/709976#M218459</guid>
      <dc:creator>HitmonTran</dc:creator>
      <dc:date>2021-01-07T17:54:07Z</dc:date>
    </item>
  </channel>
</rss>

