<?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: Sequence Number in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Sequence-Number/m-p/102996#M28833</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;i know that "sequence+1" is the same as "retain sequence 0" and sum=sum(....). What i was wondering is how after checking the first statement (if id.first) and moving to the second observation of a by group "sequence" retains its value of 1? I thought newly created variables got set to missing every time SAS begins a new iteration within a by group.I mean after meeting the first condition (&lt;STRONG&gt;if first.id then sequence = 1;) &lt;/STRONG&gt;SAS does not even know about&lt;STRONG&gt; "sequence+1" &lt;/STRONG&gt;but it instead jumps&amp;nbsp; to the second observation and still retains the value of sequence. So dont know what i am missing here&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 11 Apr 2013 19:24:24 GMT</pubDate>
    <dc:creator>Tal</dc:creator>
    <dc:date>2013-04-11T19:24:24Z</dc:date>
    <item>
      <title>Sequence Number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sequence-Number/m-p/102987#M28824</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Hi,&lt;/P&gt;&lt;P&gt;The following is the code for Sequence Number generation..&lt;/P&gt;&lt;P&gt;data sequence;&lt;/P&gt;&lt;P&gt;set final;&lt;/P&gt;&lt;P&gt;retain sequence;&lt;/P&gt;&lt;P&gt;by id;&lt;/P&gt;&lt;P&gt;if first.id then sequence=1;&lt;/P&gt;&lt;P&gt;else sequence+1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;WHY is it necessary to say &lt;STRONG&gt;retain sequence????although i am using if first.id then sequence=1;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Could you please explain with a small example???&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Thanks&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Apr 2013 17:34:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sequence-Number/m-p/102987#M28824</guid>
      <dc:creator>robertrao</dc:creator>
      <dc:date>2013-04-09T17:34:48Z</dc:date>
    </item>
    <item>
      <title>Re: Sequence Number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sequence-Number/m-p/102988#M28825</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;check out this SUGI proceeding&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings11/091-2011.pdf" title="http://support.sas.com/resources/papers/proceedings11/091-2011.pdf"&gt;http://support.sas.com/resources/papers/proceedings11/091-2011.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Doc Muhlbaier&lt;/P&gt;&lt;P&gt;Duke&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Apr 2013 17:39:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sequence-Number/m-p/102988#M28825</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2013-04-09T17:39:46Z</dc:date>
    </item>
    <item>
      <title>Re: Sequence Number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sequence-Number/m-p/102989#M28826</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The RETAIN statement is not required here. The sum statement&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;sequence + 1;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;is equivalent to&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;retain sequence 0; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;sequence = sum(sequence, 1);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Apr 2013 17:45:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sequence-Number/m-p/102989#M28826</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2013-04-09T17:45:46Z</dc:date>
    </item>
    <item>
      <title>Re: Sequence Number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sequence-Number/m-p/102990#M28827</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So if I use&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;retain sequence 0; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;sequence = sum(sequence, 1);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;therer is no need of writing this if first.condition???&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if first.id then sequence=1;&lt;/P&gt;&lt;P&gt;else sequence+1;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Apr 2013 18:05:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sequence-Number/m-p/102990#M28827</guid>
      <dc:creator>robertrao</dc:creator>
      <dc:date>2013-04-09T18:05:49Z</dc:date>
    </item>
    <item>
      <title>Re: Sequence Number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sequence-Number/m-p/102991#M28828</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your original code could be written&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data sequence;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;set final;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;by id;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;if first.id then sequence = 1;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;else sequence + 1;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data sequence;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;set final;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;retain sequence;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;by id;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;if first.id then sequence = 1;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;else sequence = sum(sequence, 1);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Apr 2013 01:26:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sequence-Number/m-p/102991#M28828</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2013-04-10T01:26:16Z</dc:date>
    </item>
    <item>
      <title>Re: Sequence Number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sequence-Number/m-p/102992#M28829</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;For sharing, just to see if it could be done without a &lt;SPAN style="font-family: 'courier new', courier;"&gt;retain&lt;/SPAN&gt; statement and an &lt;SPAN style="font-family: 'courier new', courier;"&gt;if&lt;/SPAN&gt; statement, I had some fun coming up with the following, although I wouldn't recommend it as a solution:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data sequence;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; set final;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; by id;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'courier new', courier;"&gt;&amp;nbsp; sequence+sum(first.id,first.id=0,-first.id*sequence);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;Amir.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Apr 2013 17:06:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sequence-Number/m-p/102992#M28829</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2013-04-10T17:06:56Z</dc:date>
    </item>
    <item>
      <title>Re: Sequence Number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sequence-Number/m-p/102993#M28830</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;so how come "sequence" does not get set to missing each time SAS gets to a new observation of "final"?&lt;/P&gt;&lt;P&gt;I mean it would have made sense it sequence was a part of the "final" set but in this case it&amp;nbsp; s not and still retains its&amp;nbsp; value.Is this kind of DOW?&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data sequence;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;set final;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;by id;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;if first.id then sequence = 1;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;else sequence + 1;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Apr 2013 18:01:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sequence-Number/m-p/102993#M28830</guid>
      <dc:creator>Tal</dc:creator>
      <dc:date>2013-04-11T18:01:50Z</dc:date>
    </item>
    <item>
      <title>Re: Sequence Number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sequence-Number/m-p/102994#M28831</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Because the SUM statement implies RETAIN.&amp;nbsp; Look at the online documentation.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Apr 2013 18:08:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sequence-Number/m-p/102994#M28831</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2013-04-11T18:08:37Z</dc:date>
    </item>
    <item>
      <title>Re: Sequence Number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sequence-Number/m-p/102995#M28832</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As I stated before, the presence of the statement &lt;STRONG&gt;sequence + 1&lt;/STRONG&gt; causes &lt;STRONG&gt;sequence&lt;/STRONG&gt; to be retained, just as if the statement &lt;STRONG&gt;retain sequence;&lt;/STRONG&gt; was part of your program. DOW is the nickname of a technique that includes a &lt;STRONG&gt;DO WHILE();&lt;/STRONG&gt; or &lt;STRONG&gt;DO UNTIL();&lt;/STRONG&gt; loop including &lt;STRONG&gt;SET...; BY...;&lt;/STRONG&gt; statements. It is not the case here.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Apr 2013 18:17:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sequence-Number/m-p/102995#M28832</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2013-04-11T18:17:25Z</dc:date>
    </item>
    <item>
      <title>Re: Sequence Number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sequence-Number/m-p/102996#M28833</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;i know that "sequence+1" is the same as "retain sequence 0" and sum=sum(....). What i was wondering is how after checking the first statement (if id.first) and moving to the second observation of a by group "sequence" retains its value of 1? I thought newly created variables got set to missing every time SAS begins a new iteration within a by group.I mean after meeting the first condition (&lt;STRONG&gt;if first.id then sequence = 1;) &lt;/STRONG&gt;SAS does not even know about&lt;STRONG&gt; "sequence+1" &lt;/STRONG&gt;but it instead jumps&amp;nbsp; to the second observation and still retains the value of sequence. So dont know what i am missing here&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Apr 2013 19:24:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sequence-Number/m-p/102996#M28833</guid>
      <dc:creator>Tal</dc:creator>
      <dc:date>2013-04-11T19:24:24Z</dc:date>
    </item>
    <item>
      <title>Re: Sequence Number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sequence-Number/m-p/102997#M28834</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote" modifiedtitle="true"&gt;
&lt;P&gt;Tal wrote:&lt;/P&gt;
&lt;P&gt;SAS does not even know about&lt;STRONG&gt; "sequence+1" &lt;/STRONG&gt;but it instead jumps...&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes, SAS does know that &lt;STRONG&gt;sequence&lt;/STRONG&gt; is retained because that can be determined during compilation (before execution begins). The same way it knows that &lt;STRONG&gt;sequence&lt;/STRONG&gt; is numeric and not character. The simple fact that &lt;STRONG&gt;sequence&lt;/STRONG&gt; appears in a sum statement (&lt;STRONG&gt;sequence + 1;&lt;/STRONG&gt;) anywhere in the datastep, even if that statement never executes, is enough to give it the retained status. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;hth&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Apr 2013 20:00:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sequence-Number/m-p/102997#M28834</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2013-04-11T20:00:12Z</dc:date>
    </item>
    <item>
      <title>Re: Sequence Number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sequence-Number/m-p/102998#M28835</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;i&amp;nbsp; see.That clarify my confusion.Thanks a lot &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Apr 2013 20:40:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sequence-Number/m-p/102998#M28835</guid>
      <dc:creator>Tal</dc:creator>
      <dc:date>2013-04-11T20:40:17Z</dc:date>
    </item>
  </channel>
</rss>

