<?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 Retain with Arrays in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Retain-with-Arrays/m-p/256758#M49233</link>
    <description>&lt;P&gt;I’m trying to use a simple retain with an array but the value deg_cum is producing a much larger number.&amp;nbsp; The output should be something like 1, 8, 32, and 43.&amp;nbsp; Am I missing something syntactical here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;retain deg_cum 0;&lt;BR /&gt;do i = 1 to dim(a);&lt;BR /&gt;&amp;nbsp; &amp;nbsp;deg_cum + d[i];&lt;BR /&gt;&amp;nbsp; &amp;nbsp;output;&lt;BR /&gt;end;&lt;/P&gt;</description>
    <pubDate>Tue, 15 Mar 2016 13:38:16 GMT</pubDate>
    <dc:creator>DavidPhillips2</dc:creator>
    <dc:date>2016-03-15T13:38:16Z</dc:date>
    <item>
      <title>Retain with Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-with-Arrays/m-p/256758#M49233</link>
      <description>&lt;P&gt;I’m trying to use a simple retain with an array but the value deg_cum is producing a much larger number.&amp;nbsp; The output should be something like 1, 8, 32, and 43.&amp;nbsp; Am I missing something syntactical here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;retain deg_cum 0;&lt;BR /&gt;do i = 1 to dim(a);&lt;BR /&gt;&amp;nbsp; &amp;nbsp;deg_cum + d[i];&lt;BR /&gt;&amp;nbsp; &amp;nbsp;output;&lt;BR /&gt;end;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2016 13:38:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-with-Arrays/m-p/256758#M49233</guid>
      <dc:creator>DavidPhillips2</dc:creator>
      <dc:date>2016-03-15T13:38:16Z</dc:date>
    </item>
    <item>
      <title>Re: Retain with Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-with-Arrays/m-p/256759#M49234</link>
      <description>&lt;P&gt;RETAIN is meant to keep values across data step iterations, not during DO loops.&lt;/P&gt;
&lt;P&gt;So your deg_cum will grow with every observation of your input dataset.&lt;/P&gt;
&lt;P&gt;Depending on your intention, I don't think you need the RETAIN at all.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2016 13:44:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-with-Arrays/m-p/256759#M49234</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-03-15T13:44:35Z</dc:date>
    </item>
    <item>
      <title>Re: Retain with Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-with-Arrays/m-p/256760#M49235</link>
      <description>&lt;P&gt;If you're summing the array for each observation you don't want RETAIN DEG_CUM.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to accumulate sums across observations for each array element you need and arrary of DEG_CUM1-DEC_CUMn that are also retained.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are just summing the values in ARRAY a for each obs you can use deg_cum=sum(of a[*]);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or if you don't want me to keep guessing show some data.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2016 13:45:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-with-Arrays/m-p/256760#M49235</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-03-15T13:45:28Z</dc:date>
    </item>
    <item>
      <title>Re: Retain with Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-with-Arrays/m-p/256761#M49236</link>
      <description>&lt;P&gt;&lt;SPAN&gt;This should solve it, currently testing.&lt;/SPAN&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2016 13:47:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-with-Arrays/m-p/256761#M49236</guid>
      <dc:creator>DavidPhillips2</dc:creator>
      <dc:date>2016-03-15T13:47:53Z</dc:date>
    </item>
    <item>
      <title>Re: Retain with Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-with-Arrays/m-p/256763#M49237</link>
      <description>&lt;P&gt;An additional note about this syntax:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;deg_cum + /* anything */;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This automatically retains deg_cum.&amp;nbsp; If you continue to use this (and an alternative has already been suggested), you will need to change your original RETAIN statement to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;deg_cum=0;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2016 13:53:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-with-Arrays/m-p/256763#M49237</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-03-15T13:53:59Z</dc:date>
    </item>
    <item>
      <title>Re: Retain with Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-with-Arrays/m-p/256766#M49238</link>
      <description>&lt;P&gt;Setting deg_cum to zero is alway a good idea, as it will be set to missing at the start of the current iteration of the data step.&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;deg_cum = deg_cum + ....;&lt;/FONT&gt;&amp;nbsp; would then always result in another missing value, if deg_cum was not explicitly set to something else.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2016 13:57:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-with-Arrays/m-p/256766#M49238</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-03-15T13:57:35Z</dc:date>
    </item>
    <item>
      <title>Re: Retain with Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-with-Arrays/m-p/256768#M49239</link>
      <description>&lt;P&gt;When I set&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;retain deg_cum= 0; I receive the error:&lt;BR /&gt;_&lt;BR /&gt;22&lt;BR /&gt;200&lt;BR /&gt;60 The SAS System 09:16 Tuesday, March 15, 2016&lt;/P&gt;&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant,&lt;BR /&gt;a missing value, (, -, :, ;, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_.&lt;/P&gt;&lt;P&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2016 14:00:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-with-Arrays/m-p/256768#M49239</guid>
      <dc:creator>DavidPhillips2</dc:creator>
      <dc:date>2016-03-15T14:00:01Z</dc:date>
    </item>
    <item>
      <title>Re: Retain with Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-with-Arrays/m-p/256771#M49240</link>
      <description>&lt;P&gt;Simply do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;deg_cum = 0;
do i = 1 to dim(a);
   deg_cum + d[i];
   output;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I repeat: you do &lt;U&gt;not&lt;/U&gt; need RETAIN at all, if I read your intentions right.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2016 14:01:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-with-Arrays/m-p/256771#M49240</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-03-15T14:01:42Z</dc:date>
    </item>
    <item>
      <title>Re: Retain with Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-with-Arrays/m-p/256773#M49241</link>
      <description>&lt;P&gt;Not:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;retain deg_cum=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;deg_cum=0;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2016 14:01:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-with-Arrays/m-p/256773#M49241</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-03-15T14:01:54Z</dc:date>
    </item>
    <item>
      <title>Re: Retain with Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-with-Arrays/m-p/256780#M49243</link>
      <description>&lt;P&gt;Nor DO I=1 to DIM(a); or any of it. &amp;nbsp;I can all be done with SUM function and and OF variable-list.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2016 14:14:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-with-Arrays/m-p/256780#M49243</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-03-15T14:14:24Z</dc:date>
    </item>
    <item>
      <title>Re: Retain with Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-with-Arrays/m-p/256784#M49245</link>
      <description>&lt;P&gt;You are very right, BUT:&lt;/P&gt;
&lt;P&gt;The sum(of ...) construct is very specific to SAS and may be confusing to people coming from other backgrounds.&lt;/P&gt;
&lt;P&gt;The DO loop and iterative cumulation is perfectly understandable for anybody coming from PASCAL, C, BASIC or any other procedural programming language.&lt;/P&gt;
&lt;P&gt;That's why I like to use such common constructs more, especially around here where most readers are just starting into SAS.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2016 14:20:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-with-Arrays/m-p/256784#M49245</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-03-15T14:20:36Z</dc:date>
    </item>
    <item>
      <title>Re: Retain with Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-with-Arrays/m-p/256804#M49248</link>
      <description>&lt;P&gt;I see no logic in your "reasoning".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Pretty sure the concept of a function is not beyond the comprehension of even the rankest beginner.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2016 15:38:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-with-Arrays/m-p/256804#M49248</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-03-15T15:38:27Z</dc:date>
    </item>
  </channel>
</rss>

