<?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 Cumulative sum, moving average,... with CAS actions only in Developers</title>
    <link>https://communities.sas.com/t5/Developers/Cumulative-sum-moving-average-with-CAS-actions-only/m-p/723447#M1143</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;how to calculate the classic window aggregations (like cumulative sum, moving average, moving stddev, ....) in CAS on CAS tables with CAS actions only?&lt;/P&gt;
&lt;P&gt;Datastep or fedsql are forbidden as answers &lt;span class="lia-unicode-emoji" title=":beaming_face_with_smiling_eyes:"&gt;😁&lt;/span&gt;, I don't want to reinvent the wheel and write the code for this, I need a configurable action to execute these standard calculations (like the old proc expand did).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps with the action "aggregation.aggregate"? Not sure what it does, the documentation is very unclear and there are no useful examples (&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=v_009&amp;amp;docsetId=casanpg&amp;amp;docsetTarget=cas-aggregation-aggregate.htm&amp;amp;locale=it#"&gt;https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=v_009&amp;amp;docsetId=casanpg&amp;amp;docsetTarget=cas-aggregation-aggregate.htm&amp;amp;locale=it#&lt;/A&gt;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;</description>
    <pubDate>Thu, 04 Mar 2021 16:32:07 GMT</pubDate>
    <dc:creator>Edoedoedo</dc:creator>
    <dc:date>2021-03-04T16:32:07Z</dc:date>
    <item>
      <title>Cumulative sum, moving average,... with CAS actions only</title>
      <link>https://communities.sas.com/t5/Developers/Cumulative-sum-moving-average-with-CAS-actions-only/m-p/723447#M1143</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;how to calculate the classic window aggregations (like cumulative sum, moving average, moving stddev, ....) in CAS on CAS tables with CAS actions only?&lt;/P&gt;
&lt;P&gt;Datastep or fedsql are forbidden as answers &lt;span class="lia-unicode-emoji" title=":beaming_face_with_smiling_eyes:"&gt;😁&lt;/span&gt;, I don't want to reinvent the wheel and write the code for this, I need a configurable action to execute these standard calculations (like the old proc expand did).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps with the action "aggregation.aggregate"? Not sure what it does, the documentation is very unclear and there are no useful examples (&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=v_009&amp;amp;docsetId=casanpg&amp;amp;docsetTarget=cas-aggregation-aggregate.htm&amp;amp;locale=it#"&gt;https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=v_009&amp;amp;docsetId=casanpg&amp;amp;docsetTarget=cas-aggregation-aggregate.htm&amp;amp;locale=it#&lt;/A&gt;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 16:32:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Cumulative-sum-moving-average-with-CAS-actions-only/m-p/723447#M1143</guid>
      <dc:creator>Edoedoedo</dc:creator>
      <dc:date>2021-03-04T16:32:07Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative sum, moving average,... with CAS actions only</title>
      <link>https://communities.sas.com/t5/Developers/Cumulative-sum-moving-average-with-CAS-actions-only/m-p/748896#M1215</link>
      <description>&lt;P&gt;Here is a little bit of code to get you started:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;cas mySession;
libname casuser cas caslib="casuser" sessref="mySession";

data casuser.test;
	do i=1 to 12;
		do y=2020 to 2021;
			date=mdy(i, 1, y);
			total=round(rand("uniform", 1, 10));
			output;
		end;
	end;
	format date date9.;
	drop i y;
run;

proc cas;
	tbl={name="test", caslib="casuser"};
	table.fetch / table=tbl, index=FALSE;
	aggregation.aggregate / 
        table=tbl || {groupBy="Date"}
	   ,varSpecs={{name="Total", subset="MEAN"} }
       ,ID="Date"
       ,Interval="MONTH"
       ,windowInt="QTR"
       ,casOut={name="summary", caslib="casuser", replace=TRUE}
    ;
	table.fetch / 
		 table={name="summary", caslib="casuser", orderBy={"date"}}
		,index=FALSE
     ;
quit;

proc expand data=casuser.test 
            out=Stats;
   id  Date;
   convert Total=_total_Summary_Mean_ / transout=(movave 3  trimleft 2);
run;

proc compare base=stats compare=casuser.summary brief transpose;
  id date;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;PROC COMPARE results show minute, insignificant differences in the calculated values for a few rows, but otherwise results are identical:&lt;/P&gt;
&lt;PRE&gt;The COMPARE Procedure
Comparison of WORK.STATS with CASUSER.SUMMARY
(Method=EXACT)
Comparison Results for Observations

date=01OCT2020:
Variable Base Value Compare Diff. % Diff
_total_Summary_Mean_ 5.000000 5 -8.88178E-16 -1.77636E-14

date=01MAR2021:
Variable Base Value Compare Diff. % Diff
_total_Summary_Mean_ 4.333333 4.3333333333 8.881784E-16 2.049643E-14

date=01MAY2021:
Variable Base Value Compare Diff. % Diff
_total_Summary_Mean_ 4.333333 4.3333333333 -8.88178E-16 -2.04964E-14

date=01DEC2021:
Variable Base Value Compare Diff. % Diff
_total_Summary_Mean_ 6.000000 6 2.664535E-15 4.440892E-14

NOTE: Values of the following 1 variables compare unequal: _total_Summary_Mean_
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jun 2021 14:14:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Cumulative-sum-moving-average-with-CAS-actions-only/m-p/748896#M1215</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2021-06-18T14:14:55Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative sum, moving average,... with CAS actions only</title>
      <link>https://communities.sas.com/t5/Developers/Cumulative-sum-moving-average-with-CAS-actions-only/m-p/748967#M1216</link>
      <description>&lt;P&gt;I have no idea of whether the CAS approach is more or less &lt;U&gt;efficient&lt;/U&gt; than proc expand for sorted data from a sas data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But it's certainly more &lt;U&gt;flexible&lt;/U&gt;.&amp;nbsp; A major shortcoming (IMO) of PROC EXPAND, is that it only provides univariate statistics for windows.&amp;nbsp; An equivalent ordinary data step (and I presume an equivalent PROC CAS) would be much superior to proc expand in generating rolling window bivariate/multivariate stats - for example generating rolling windows sums-of-squares-and-cross-products (SSCP).&amp;nbsp; A rolling window SSCP is ready-made for rolling-window regressions.&amp;nbsp; &amp;nbsp;PROC EXPAND can't do that unless you pre-process the data to generate observation-by-observation individual cross-products.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13728"&gt;@SASJedi&lt;/a&gt;&amp;nbsp;, may I shift &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/5590"&gt;@Edoedoedo&lt;/a&gt;&amp;nbsp;'s goal posts a bit.&amp;nbsp; Might we see CAS actions to generate rolling SSCP?&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jun 2021 17:56:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Cumulative-sum-moving-average-with-CAS-actions-only/m-p/748967#M1216</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-06-18T17:56:28Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative sum, moving average,... with CAS actions only</title>
      <link>https://communities.sas.com/t5/Developers/Cumulative-sum-moving-average-with-CAS-actions-only/m-p/750775#M1219</link>
      <description>&lt;P&gt;I'm going to admit right here that I am not statistically inclined, and CSSP is not one of the statistics I'm familiar with - nor is it supported by the &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/v_014/casanpg/cas-aggregation-aggregate.htm#SAS.cas-aggregation-aggregate-varspecs-summarysubset" target="_self"&gt;&lt;STRONG&gt;aggregation.aggregate&lt;/STRONG&gt;&lt;/A&gt;&amp;nbsp;CAS action.&amp;nbsp; But your post suggests you may know how to accomplish what you need with DATA step code. If so, give the &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/v_006/caspg/cas-datastep-runcode.htm" target="_self"&gt;dataStep.runCode&lt;/A&gt; action a whirl &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Jun 2021 11:40:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Cumulative-sum-moving-average-with-CAS-actions-only/m-p/750775#M1219</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2021-06-28T11:40:45Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative sum, moving average,... with CAS actions only</title>
      <link>https://communities.sas.com/t5/Developers/Cumulative-sum-moving-average-with-CAS-actions-only/m-p/829605#M6141</link>
      <description>&lt;P&gt;Since there is a set of really good cumulative functions in VA I guess there must be a use of the aggregate function. What I really want is the cumulative month to date average for all days in a month and a YTD&amp;nbsp; cumulative for all the days in a year.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Traditionally I've always done these sort of tasks with a datastep. That need the data sorted and retain. But I would love to sse how this have been achieved in VA&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Pål N&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 06:58:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Cumulative-sum-moving-average-with-CAS-actions-only/m-p/829605#M6141</guid>
      <dc:creator>PaalNavestad</dc:creator>
      <dc:date>2022-08-22T06:58:20Z</dc:date>
    </item>
  </channel>
</rss>

