<?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: plotting cumulative sums without prior calculation in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/plotting-cumulative-sums-without-prior-calculation/m-p/319409#M11183</link>
    <description>&lt;P&gt;You might try CDFPLOT in Proc Unvariate as a start.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not sure what a cumulative plot over a categorical like name would mean. There is no actual meaning to the order of names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 16 Dec 2016 00:09:32 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2016-12-16T00:09:32Z</dc:date>
    <item>
      <title>plotting cumulative sums without prior calculation</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/plotting-cumulative-sums-without-prior-calculation/m-p/319403#M11180</link>
      <description>&lt;P&gt;Hello SAS folks –&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will be making several series of graphics using cumulative sums at several different aggregation levels. I have been reading the SGPLOT documentation to see if there is anything I can use to generate the plots without having to actually calculate the cumulative totals beforehand, but no luck so far. If someone can point the way, I would be very grateful.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Most of the aggregations will be based on date (year, fiscal year, month, week), but we also have text categories as well, and possibly some combinations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We are running 9.4M3 on a Windows server via remote login. We do have SAS/GRAPH, but I would prefer to use SG if possible, as I have quite a bit of existing code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I made up a little example dataset, with date, person, and amount as variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The graphics must have “Date” on the X axis, and “Amount” on the Y axis. The code at the bottom gives a single graph with one line for each person. I also tried tinkering with FREQ and UNIVARIATE with no success on getting the axes correct. The closest I got was reversed axes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Graph 1: cumulative sum by date:&lt;/P&gt;
&lt;P&gt;X= 12/01/2016 &amp;nbsp;&amp;nbsp;&amp;nbsp;Y=170 &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;(10 from Lisa + 100 from John + 60 from Wendy)&lt;/P&gt;
&lt;P&gt;X= 12/03/2016 &amp;nbsp;&amp;nbsp;&amp;nbsp;Y= 390 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;(170 + 20 from Lisa + 200 from John)&lt;/P&gt;
&lt;P&gt;X=12/10/2016 &amp;nbsp;&amp;nbsp; &amp;nbsp;Y= 540 &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;(390 + 150 from Steve)&lt;/P&gt;
&lt;P&gt;etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Graph 2 (series): cumulative sum by date by person:&lt;/P&gt;
&lt;P&gt;X= 12/01/2016 &amp;nbsp;&amp;nbsp;&amp;nbsp;person=Lisa&amp;nbsp;&amp;nbsp; Y=10 &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;X= 12/01/2016 &amp;nbsp;&amp;nbsp;&amp;nbsp;person=Lisa&amp;nbsp;&amp;nbsp; Y=30 (10 + 20) &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for any help you can give me!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Wendy T&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 sample ;
input  Date  mmddyy10.  Person $ Amount ;
format date mmddyy10. ;
datalines ;
12/01/2016 Lisa   10
12/01/2016 John   100   
12/01/2016 Wendy  60   
12/03/2016 Lisa   20    
12/03/2016 John   200   
12/10/2016 Steve  150   
12/10/2016 Wendy  30    
12/11/2016 Lisa   80    
12/11/2016 John   100   
12/11/2016 Steve  80    
12/11/2016 Wendy  20    
12/12/2016 John   50    
12/15/2016 Steve  20    
12/15/2016 Wendy  20    
12/17/2016 Steve  100   
12/17/2016 Wendy  100   
12/28/2016 Steve  180   
12/28/2016 Steve  50    
12/29/2016 Lisa   50    
12/30/2016 Wendy  20    
;
run ;


%let OUTDIR= YourDirectory ;

ods listing close ;
ods graphics on /  reset=index imagename="graph" height=480px width=1280px imagemap=on ;

ods html newfile=none headtext='&amp;lt;style&amp;gt;p,hr {display:none} &amp;lt;/style&amp;gt;' 
    path="&amp;amp;OUTDIR\" (url=none)
    body="body.htm" contents="contents.htm" frame="frame.html" ;

proc sgplot data=sample ;
  series x=date y=amount / markers group=person ;
run ;

ods html close ;
ods listing ;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Dec 2016 23:40:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/plotting-cumulative-sums-without-prior-calculation/m-p/319403#M11180</guid>
      <dc:creator>WendyT</dc:creator>
      <dc:date>2016-12-15T23:40:42Z</dc:date>
    </item>
    <item>
      <title>Re: plotting cumulative sums without prior calculation</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/plotting-cumulative-sums-without-prior-calculation/m-p/319409#M11183</link>
      <description>&lt;P&gt;You might try CDFPLOT in Proc Unvariate as a start.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not sure what a cumulative plot over a categorical like name would mean. There is no actual meaning to the order of names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2016 00:09:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/plotting-cumulative-sums-without-prior-calculation/m-p/319409#M11183</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-12-16T00:09:32Z</dc:date>
    </item>
    <item>
      <title>Re: plotting cumulative sums without prior calculation</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/plotting-cumulative-sums-without-prior-calculation/m-p/319536#M11188</link>
      <description>&lt;P&gt;I'm mostly guessing, but are you trying to plot the cumulative amounts for each person by date? &amp;nbsp;If so, then this is a form of &lt;A title="Create spaghetti plots in SAS" href="http://blogs.sas.com/content/iml/2016/06/02/create-spaghetti-plots-in-sas.html" target="_self"&gt;a spaghetti plot.&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;You can use a DATA step to form the cumulative sum, then use the SGPLOT code that you provided to plot the series for each person:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sample;
by Person date;
run;

data cusum;
set sample;
by person;
if first.Person then cusum = 0;
cusum + Amount;
run;

proc sgplot data=cusum;
label cusum = "Cumulative Amount";
  series x=date y=cusum / markers group=person ;
run ;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Dec 2016 13:01:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/plotting-cumulative-sums-without-prior-calculation/m-p/319536#M11188</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2016-12-16T13:01:11Z</dc:date>
    </item>
    <item>
      <title>Re: plotting cumulative sums without prior calculation</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/plotting-cumulative-sums-without-prior-calculation/m-p/319592#M11190</link>
      <description>&lt;P&gt;ballardw and Rick_SAS-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the code, and I'll take a look at UNIVARIATE and the spaghetti plots.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry to be unclear... I oversimplified.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I'm working on at the moment&amp;nbsp;is&amp;nbsp;fisheries data:&amp;nbsp; pounds of fish caught,&amp;nbsp;price paid for the fish, fishermen and numbers of boats fishing, net&amp;nbsp;size data,&amp;nbsp;etc. etc. etc., and just to make it more challenging, I&amp;nbsp;have&amp;nbsp;multiple lakes with different fishing seasons over both calendar and fiscal years.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My hope was to be able to write a macro for general plots of a type, then pass in appropriate BY variables, time groupings via formats, etc. I've done similar things with water quality data with a macro that runs PROC MEANS, outputs to a dataset, then plots from there.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, my sticky bit has been&amp;nbsp;cumulative catch and cost data, and catch per unit effort, as the calculations change based on the groupings.&amp;nbsp;&amp;nbsp;I was hoping that&amp;nbsp;SGPLOT could handle the cumulative part, so I didn't have&amp;nbsp;to do the extra&amp;nbsp;sorts and data steps.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A few examples might be:&amp;nbsp;Total fish caught by Lake by FY, Catch by fisherman by FY, Catch per unit effort&amp;nbsp;by&amp;nbsp;Lake, Catch per unit effort by fisherman by time (FY, year, month, week), etc. etc. etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks so much for your help!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Wendy T.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2016 16:49:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/plotting-cumulative-sums-without-prior-calculation/m-p/319592#M11190</guid>
      <dc:creator>WendyT</dc:creator>
      <dc:date>2016-12-16T16:49:45Z</dc:date>
    </item>
  </channel>
</rss>

