<?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: Making COUNTER as a field by do loop – not working properly in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Making-COUNTER-as-a-field-by-do-loop-not-working-properly/m-p/10314#M739</link>
    <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
In the case you still have the problem unsolved, it will be good to explain the purpose of the code (you are saying something in the subject line) and  provide a sample of the data. Also the log could be useful.&lt;BR /&gt;
&lt;BR /&gt;
Warm regards,&lt;BR /&gt;
Vasile</description>
    <pubDate>Tue, 15 Feb 2011 20:21:06 GMT</pubDate>
    <dc:creator>Vasile01</dc:creator>
    <dc:date>2011-02-15T20:21:06Z</dc:date>
    <item>
      <title>Making COUNTER as a field by do loop – not working properly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-COUNTER-as-a-field-by-do-loop-not-working-properly/m-p/10310#M735</link>
      <description>Here is the basic structure of my code:&lt;BR /&gt;
DATA SUSBUILD0;                               &lt;BR /&gt;
  SET SUSBUILD0;                              &lt;BR /&gt;
  LENGTH COUNTER 2;                           &lt;BR /&gt;
  COUNTER eq 1;                                &lt;BR /&gt;
  LAGPID eq LAG(PID);                            &lt;BR /&gt;
  LAGBENTYPE eq LAG(BEN_TYPE_CODE);              &lt;BR /&gt;
  IF _N_ GT 1 THEN                             &lt;BR /&gt;
    DO;                                       &lt;BR /&gt;
      IF (LAGPID eq PID AND                    &lt;BR /&gt;
          LAGBENTYPE eq BEN_TYPE_CODE)      &lt;BR /&gt;
      THEN                                    &lt;BR /&gt;
         COUNTER eq COUNTER + 1;               &lt;BR /&gt;
    END;                                      &lt;BR /&gt;
RETURN;           &lt;BR /&gt;
Looks like this do loop can be only visited once and stop or somehow as it loops through, it always carries the old memory that COUNTER eq 1, so COUNTER becomes 1 + 1 eq 2. As a matter of fact, none of my output records have COUNTER carry values either than 1 or 2.&lt;BR /&gt;
I have a feeling that there must be something simple I have missed in my do loop. Sorry for I asked such a dump question.</description>
      <pubDate>Tue, 15 Feb 2011 06:30:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-COUNTER-as-a-field-by-do-loop-not-working-properly/m-p/10310#M735</guid>
      <dc:creator>willow2010</dc:creator>
      <dc:date>2011-02-15T06:30:03Z</dc:date>
    </item>
    <item>
      <title>Re: Making COUNTER as a field by do loop – not working properly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-COUNTER-as-a-field-by-do-loop-not-working-properly/m-p/10311#M736</link>
      <description>change the COUNTER+1 statement from[pre] counter= counter+1;[/pre] to[pre] Counter+1;[/pre] there seem to be many other features in the code you posted that I have not seen among the examples available in SAS documentation on-line. &lt;BR /&gt;
Why do you use EQ for assignment rather than the symbol "=" ?&lt;BR /&gt;
 hth&lt;BR /&gt;
peterC</description>
      <pubDate>Tue, 15 Feb 2011 08:51:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-COUNTER-as-a-field-by-do-loop-not-working-properly/m-p/10311#M736</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-02-15T08:51:14Z</dc:date>
    </item>
    <item>
      <title>Re: Making COUNTER as a field by do loop – not working properly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-COUNTER-as-a-field-by-do-loop-not-working-properly/m-p/10312#M737</link>
      <description>If you want to maintain the value of COUNTER over multiple iterations of the data step, then you need to add the RETAIN COUNTER statement.</description>
      <pubDate>Tue, 15 Feb 2011 12:19:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-COUNTER-as-a-field-by-do-loop-not-working-properly/m-p/10312#M737</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2011-02-15T12:19:04Z</dc:date>
    </item>
    <item>
      <title>Re: Making COUNTER as a field by do loop – not working properly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-COUNTER-as-a-field-by-do-loop-not-working-properly/m-p/10313#M738</link>
      <description>Using the nomenclature Counter+1 (vs. counter = counter + 1) is an implicit retain.</description>
      <pubDate>Tue, 15 Feb 2011 19:26:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-COUNTER-as-a-field-by-do-loop-not-working-properly/m-p/10313#M738</guid>
      <dc:creator>DavidJ</dc:creator>
      <dc:date>2011-02-15T19:26:07Z</dc:date>
    </item>
    <item>
      <title>Re: Making COUNTER as a field by do loop – not working properly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-COUNTER-as-a-field-by-do-loop-not-working-properly/m-p/10314#M739</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
In the case you still have the problem unsolved, it will be good to explain the purpose of the code (you are saying something in the subject line) and  provide a sample of the data. Also the log could be useful.&lt;BR /&gt;
&lt;BR /&gt;
Warm regards,&lt;BR /&gt;
Vasile</description>
      <pubDate>Tue, 15 Feb 2011 20:21:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-COUNTER-as-a-field-by-do-loop-not-working-properly/m-p/10314#M739</guid>
      <dc:creator>Vasile01</dc:creator>
      <dc:date>2011-02-15T20:21:06Z</dc:date>
    </item>
    <item>
      <title>Re: Making COUNTER as a field by do loop – not working properly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-COUNTER-as-a-field-by-do-loop-not-working-properly/m-p/10315#M740</link>
      <description>Thank you for all of your joint efforts. Now my code works!&lt;BR /&gt;
DATA SUSBUILD0;                             &lt;BR /&gt;
  SET SUSBUILD0;                            &lt;BR /&gt;
  LENGTH COUNTER 2;                &lt;BR /&gt;
  LAGPID=LAG(PID);                          &lt;BR /&gt;
  LAGBENTYPE=LAG(BEN_TYPE_CODE);            &lt;BR /&gt;
  IF _N_ GT 1 THEN                           &lt;BR /&gt;
    DO;                                     &lt;BR /&gt;
      IF (LAGPID = PID AND                  &lt;BR /&gt;
          LAGBENTYPE = BEN_TYPE_CODE)    &lt;BR /&gt;
      THEN                                  &lt;BR /&gt;
         COUNTER + 1;              &lt;BR /&gt;
      ELSE                                  &lt;BR /&gt;
         COUNTER = 1;              &lt;BR /&gt;
    END;                                    &lt;BR /&gt;
RETURN;                    &lt;BR /&gt;
The reason for me to put eq instead of = before was in concern whether = will be read as HTML tag, obviously not, it if the GT sign I need to be careful.                 &lt;BR /&gt;
&lt;BR /&gt;
Cheers to you all!</description>
      <pubDate>Wed, 16 Feb 2011 00:04:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-COUNTER-as-a-field-by-do-loop-not-working-properly/m-p/10315#M740</guid>
      <dc:creator>willow2010</dc:creator>
      <dc:date>2011-02-16T00:04:06Z</dc:date>
    </item>
    <item>
      <title>Re: Making COUNTER as a field by do loop – not working properly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-COUNTER-as-a-field-by-do-loop-not-working-properly/m-p/10316#M741</link>
      <description>Ooh, I forgot to put the line RETAIN COUNTER 1; just under LENGTH COUNTER 2 to get the very first record works.&lt;BR /&gt;
&lt;BR /&gt;
: )</description>
      <pubDate>Wed, 16 Feb 2011 00:19:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-COUNTER-as-a-field-by-do-loop-not-working-properly/m-p/10316#M741</guid>
      <dc:creator>willow2010</dc:creator>
      <dc:date>2011-02-16T00:19:16Z</dc:date>
    </item>
  </channel>
</rss>

