<?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: SAS retain 0 to find maximum value concept in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-retain-0-to-find-maximum-value-concept/m-p/840048#M332151</link>
    <description>&lt;P&gt;RETAIN is a declarative statement, not an executable one.&lt;/P&gt;
&lt;P&gt;The value is used once during data step compilation to initialize the variable.&lt;/P&gt;</description>
    <pubDate>Sat, 22 Oct 2022 06:04:50 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-10-22T06:04:50Z</dc:date>
    <item>
      <title>SAS retain 0 to find maximum value concept</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-retain-0-to-find-maximum-value-concept/m-p/840041#M332147</link>
      <description>&lt;P&gt;Hi I am doing Programming 2 lesson 2 on trying to find maximum traffic count using RETAIN statement, the example code is as follow:&lt;/P&gt;
&lt;PRE&gt;data cuyahoga_maxtraffic;
    set pg2.np_monthlyTraffic;
    where ParkName = 'Cuyahoga Valley NP';
    retain TrafficMax 0 MonthMax LocationMax;
    if Count&amp;gt;TrafficMax then do;
        TrafficMax=Count;
        MonthMax=Month;
        LocationMax=Location;
    end;
    format Count TrafficMax comma15.;
    keep Location Month Count TrafficMax MonthMax LocationMax;
run;&lt;/PRE&gt;
&lt;P&gt;I am trying to understand why retain TrafficMax 0? Wouldn't that set the TrafficMax to 0 every row iteration?&lt;/P&gt;
&lt;P&gt;for example if row 1 count is 5 and row 2 count is 4 then&lt;/P&gt;
&lt;P&gt;TrafficMax is 0 after retain TrafficMax 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;then it is set to 5 after iteration of row 1, then TrafficMax is set back as 0 at the beginning of iteration of row 2, and TrafficMax is set to 4 after iteration of row 2?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or am I misunderstanding the SAS compiling process, only the if/then statement is looped for each row?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Oct 2022 00:08:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-retain-0-to-find-maximum-value-concept/m-p/840041#M332147</guid>
      <dc:creator>Nietzsche</dc:creator>
      <dc:date>2022-10-22T00:08:41Z</dc:date>
    </item>
    <item>
      <title>Re: SAS retain 0 to find maximum value concept</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-retain-0-to-find-maximum-value-concept/m-p/840042#M332148</link>
      <description>&lt;P&gt;Also adding the 0 in the RETAIN statement does not seem to affect TrafficMax or MonthMax but LocationMax becomes empty. Why is that?&lt;/P&gt;</description>
      <pubDate>Sat, 22 Oct 2022 00:16:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-retain-0-to-find-maximum-value-concept/m-p/840042#M332148</guid>
      <dc:creator>Nietzsche</dc:creator>
      <dc:date>2022-10-22T00:16:00Z</dc:date>
    </item>
    <item>
      <title>Re: SAS retain 0 to find maximum value concept</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-retain-0-to-find-maximum-value-concept/m-p/840048#M332151</link>
      <description>&lt;P&gt;RETAIN is a declarative statement, not an executable one.&lt;/P&gt;
&lt;P&gt;The value is used once during data step compilation to initialize the variable.&lt;/P&gt;</description>
      <pubDate>Sat, 22 Oct 2022 06:04:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-retain-0-to-find-maximum-value-concept/m-p/840048#M332151</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-10-22T06:04:50Z</dc:date>
    </item>
    <item>
      <title>Re: SAS retain 0 to find maximum value concept</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-retain-0-to-find-maximum-value-concept/m-p/840049#M332152</link>
      <description>&lt;P&gt;By adding the zero in the RETAIN statement, you define the variable as numeric, so it can't hold the character values of location.&lt;/P&gt;
&lt;P&gt;Without the zero, the type of the variable is set later during compilation when the assignment statement is encountered.&lt;/P&gt;</description>
      <pubDate>Sat, 22 Oct 2022 06:08:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-retain-0-to-find-maximum-value-concept/m-p/840049#M332152</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-10-22T06:08:32Z</dc:date>
    </item>
    <item>
      <title>Re: SAS retain 0 to find maximum value concept</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-retain-0-to-find-maximum-value-concept/m-p/840050#M332153</link>
      <description>&lt;P&gt;PS read the log (Maxim 2). You'll find NOTEs about invalid numeric data.&lt;/P&gt;</description>
      <pubDate>Sat, 22 Oct 2022 06:09:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-retain-0-to-find-maximum-value-concept/m-p/840050#M332153</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-10-22T06:09:53Z</dc:date>
    </item>
  </channel>
</rss>

