<?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: Retain statement initial value in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Retain-statement-initial-value/m-p/169570#M43862</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The initialization of all variables, retained or not, takes place at compilation time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Some variables get re-initialized to missing during the execution phase of the DATA step.&amp;nbsp; The RETAIN statement merely tells SAS to skip re-initializing the variable during the execution phase.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the RETAIN statement does not supply an initial value, the initial value is missing.&amp;nbsp; However, note that a "sum" statement is related to the concept of RETAIN and initial values:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;tot + 1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This statement means that TOT will be retained, and will be given an initial value of zero during the compilation phase of the DATA step.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 05 Jan 2015 21:46:17 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2015-01-05T21:46:17Z</dc:date>
    <item>
      <title>Retain statement initial value</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Retain-statement-initial-value/m-p/169568#M43860</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have question regarding initialization of retain statement:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If we do not provide any initial value to variable in retain statement then where it will initialize? during compile time or during execution? and to what value: missing or zero?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Jan 2015 20:58:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Retain-statement-initial-value/m-p/169568#M43860</guid>
      <dc:creator>parveeniitk</dc:creator>
      <dc:date>2015-01-05T20:58:52Z</dc:date>
    </item>
    <item>
      <title>Re: Retain statement initial value</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Retain-statement-initial-value/m-p/169569#M43861</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Execution time - Missing&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Jan 2015 21:33:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Retain-statement-initial-value/m-p/169569#M43861</guid>
      <dc:creator>CTorres</dc:creator>
      <dc:date>2015-01-05T21:33:50Z</dc:date>
    </item>
    <item>
      <title>Re: Retain statement initial value</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Retain-statement-initial-value/m-p/169570#M43862</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The initialization of all variables, retained or not, takes place at compilation time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Some variables get re-initialized to missing during the execution phase of the DATA step.&amp;nbsp; The RETAIN statement merely tells SAS to skip re-initializing the variable during the execution phase.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the RETAIN statement does not supply an initial value, the initial value is missing.&amp;nbsp; However, note that a "sum" statement is related to the concept of RETAIN and initial values:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;tot + 1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This statement means that TOT will be retained, and will be given an initial value of zero during the compilation phase of the DATA step.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Jan 2015 21:46:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Retain-statement-initial-value/m-p/169570#M43862</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-01-05T21:46:17Z</dc:date>
    </item>
    <item>
      <title>Re: Retain statement initial value</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Retain-statement-initial-value/m-p/169571#M43863</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have two (2) follow up questions:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) Can you give us an example of which variables get re-initialized during the execution phase? I thought execution is merely read and write (and calcuation if that applies).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2) What happens if you retain a variable with a valid value that is being read. For example, say variable x=2 in the first observation and I wrote a line of code as follows: retain x;. Doesn't that mean the value of 2 is retained in PDV during the initialization of the PDV in the second iteration of the DATA step?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;M.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Jan 2015 21:54:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Retain-statement-initial-value/m-p/169571#M43863</guid>
      <dc:creator>MaikH_Schutze</dc:creator>
      <dc:date>2015-01-05T21:54:31Z</dc:date>
    </item>
    <item>
      <title>Re: Retain statement initial value</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Retain-statement-initial-value/m-p/169572#M43864</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For question 1, I think this is the complete list.&amp;nbsp; The DATA step retains (a) any variable mentioned in a RETAIN statement, (b) the first variable in a SUM statement, and (c) any variable that comes from a SAS data set (regardless of whether the SAS data set is being read with a SET, MERGE, or UPDATE statement).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For question 2, yes the variable is retained.&amp;nbsp; Your programming statements may overwrite that retained value, however.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To illustrate, you might try creating some variations on these programs:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; put 'Before:&amp;nbsp; ' x=;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; input dummy;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; retain x;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; x=_n_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; put 'After:&amp;nbsp; ' x=;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;8&lt;/P&gt;&lt;P&gt;9&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; put 'Before:&amp;nbsp; ' x=;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set test1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; x=_n_ + 10;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; put 'After:&amp;nbsp; ' x=;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Jan 2015 22:05:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Retain-statement-initial-value/m-p/169572#M43864</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-01-05T22:05:22Z</dc:date>
    </item>
  </channel>
</rss>

