<?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: number rows from 1 to 3 only on criteria in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/number-rows-from-1-to-3-only-on-criteria/m-p/766819#M243053</link>
    <description>&lt;P&gt;Hello Peter,&lt;/P&gt;
&lt;P&gt;how to do that with many names ? look at "have2" dataset.&lt;/P&gt;
&lt;P&gt;the flag should start with 1 when a new group name starts.&lt;/P&gt;
&lt;P&gt;many thanks&lt;/P&gt;
&lt;PRE&gt;Data have2  ;
infile datalines ;
input name $ week i_jour_sem i_sem ;
datalines ;
Andrew 39 1 1
Andrew 39 2 1
Andrew 39 3 1
Andrew 39 4 1
Andrew 39 5 1
Andrew 40 1 2
Andrew 40 2 2
Andrew 40 3 2
Andrew 40 4 2
Andrew 40 5 2
Andrew 41 1 3
Andrew 41 2 3
Andrew 41 3 3
Andrew 41 4 3
Andrew 41 5 3
Andrew 42 1 4
Andrew 42 2 4
Andrew 42 3 4
Andrew 42 4 4
Andrew 42 5 4
Andrew 43 1 5
Andrew 43 2 5
Andrew 43 3 5
Andrew 43 4 5
Andrew 43 5 5
Andrew 44 1 6
Andrew 44 2 6
Andrew 44 3 6
Andrew 44 4 6
Andrew 44 5 6
Dalila 39 1 1
Dalila 39 2 1
Dalila 39 3 1
Dalila 39 4 1
Dalila 39 5 1
Dalila 40 1 2
Dalila 40 2 2
Dalila 40 3 2
Dalila 40 4 2
Dalila 40 5 2
Dalila 41 1 3
Dalila 41 2 3
Dalila 41 3 3
Dalila 41 4 3
Dalila 41 5 3
Dalila 42 1 4
Dalila 42 2 4
Dalila 42 3 4
Dalila 42 4 4
Dalila 42 5 4
Dalila 43 1 5
Dalila 43 2 5
Dalila 43 3 5
Dalila 43 4 5
Dalila 43 5 5
Dalila 44 1 6
Dalila 44 2 6
Dalila 44 3 6
Dalila 44 4 6
;
run ;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 09 Sep 2021 11:46:15 GMT</pubDate>
    <dc:creator>Nasser_DRMCP</dc:creator>
    <dc:date>2021-09-09T11:46:15Z</dc:date>
    <item>
      <title>number rows from 1 to 3 only on criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/number-rows-from-1-to-3-only-on-criteria/m-p/766785#M243039</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in this dataset "have". i would like to get a flag populated only when i_jour_sem = i_sem.&lt;/P&gt;
&lt;P&gt;the first time that this criteria is met then the flag shoul be 1, the second time then 2, the 3è then 3, but the 4 times the 1, the 5 times then 2 ...&lt;/P&gt;
&lt;P&gt;so , only whenever &amp;nbsp;i_jour_sem = i_sem.the flag should be 1,2,3,1,2,3...&lt;/P&gt;
&lt;P&gt;thanks for your help in advance&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;PRE&gt;Data have  ;
infile datalines ;
input name $ week i_jour_sem i_sem ;
datalines ;
Andrew 39 1 1
Andrew 39 2 1
Andrew 39 3 1
Andrew 39 4 1
Andrew 39 5 1
Andrew 40 1 2
Andrew 40 2 2
Andrew 40 3 2
Andrew 40 4 2
Andrew 40 5 2
Andrew 41 1 3
Andrew 41 2 3
Andrew 41 3 3
Andrew 41 4 3
Andrew 41 5 3
Andrew 42 1 4
Andrew 42 2 4
Andrew 42 3 4
Andrew 42 4 4
Andrew 42 5 4
Andrew 43 1 5
Andrew 43 2 5
Andrew 43 3 5
Andrew 43 4 5
Andrew 43 5 5
Andrew 44 1 6
Andrew 44 2 6
Andrew 44 3 6
Andrew 44 4 6
Andrew 44 5 6
;
run ;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Sep 2021 08:56:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/number-rows-from-1-to-3-only-on-criteria/m-p/766785#M243039</guid>
      <dc:creator>Nasser_DRMCP</dc:creator>
      <dc:date>2021-09-09T08:56:25Z</dc:date>
    </item>
    <item>
      <title>Re: number rows from 1 to 3 only on criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/number-rows-from-1-to-3-only-on-criteria/m-p/766787#M243041</link>
      <description>&lt;P&gt;What about when the values are unequal? Should the flag be missing?&lt;/P&gt;</description>
      <pubDate>Thu, 09 Sep 2021 09:02:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/number-rows-from-1-to-3-only-on-criteria/m-p/766787#M243041</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-09-09T09:02:48Z</dc:date>
    </item>
    <item>
      <title>Re: number rows from 1 to 3 only on criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/number-rows-from-1-to-3-only-on-criteria/m-p/766790#M243044</link>
      <description>yes.</description>
      <pubDate>Thu, 09 Sep 2021 09:17:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/number-rows-from-1-to-3-only-on-criteria/m-p/766790#M243044</guid>
      <dc:creator>Nasser_DRMCP</dc:creator>
      <dc:date>2021-09-09T09:17:32Z</dc:date>
    </item>
    <item>
      <title>Re: number rows from 1 to 3 only on criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/number-rows-from-1-to-3-only-on-criteria/m-p/766803#M243045</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop = c);
   set have;
   if i_jour_sem ne i_sem then flag = .;

   else do;
      flag = sum(c, 1);
      c = sum(c, 1);
   end;
   
   if c = 3 then c = 0;
   retain c;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Sep 2021 10:09:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/number-rows-from-1-to-3-only-on-criteria/m-p/766803#M243045</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-09-09T10:09:03Z</dc:date>
    </item>
    <item>
      <title>Re: number rows from 1 to 3 only on criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/number-rows-from-1-to-3-only-on-criteria/m-p/766819#M243053</link>
      <description>&lt;P&gt;Hello Peter,&lt;/P&gt;
&lt;P&gt;how to do that with many names ? look at "have2" dataset.&lt;/P&gt;
&lt;P&gt;the flag should start with 1 when a new group name starts.&lt;/P&gt;
&lt;P&gt;many thanks&lt;/P&gt;
&lt;PRE&gt;Data have2  ;
infile datalines ;
input name $ week i_jour_sem i_sem ;
datalines ;
Andrew 39 1 1
Andrew 39 2 1
Andrew 39 3 1
Andrew 39 4 1
Andrew 39 5 1
Andrew 40 1 2
Andrew 40 2 2
Andrew 40 3 2
Andrew 40 4 2
Andrew 40 5 2
Andrew 41 1 3
Andrew 41 2 3
Andrew 41 3 3
Andrew 41 4 3
Andrew 41 5 3
Andrew 42 1 4
Andrew 42 2 4
Andrew 42 3 4
Andrew 42 4 4
Andrew 42 5 4
Andrew 43 1 5
Andrew 43 2 5
Andrew 43 3 5
Andrew 43 4 5
Andrew 43 5 5
Andrew 44 1 6
Andrew 44 2 6
Andrew 44 3 6
Andrew 44 4 6
Andrew 44 5 6
Dalila 39 1 1
Dalila 39 2 1
Dalila 39 3 1
Dalila 39 4 1
Dalila 39 5 1
Dalila 40 1 2
Dalila 40 2 2
Dalila 40 3 2
Dalila 40 4 2
Dalila 40 5 2
Dalila 41 1 3
Dalila 41 2 3
Dalila 41 3 3
Dalila 41 4 3
Dalila 41 5 3
Dalila 42 1 4
Dalila 42 2 4
Dalila 42 3 4
Dalila 42 4 4
Dalila 42 5 4
Dalila 43 1 5
Dalila 43 2 5
Dalila 43 3 5
Dalila 43 4 5
Dalila 43 5 5
Dalila 44 1 6
Dalila 44 2 6
Dalila 44 3 6
Dalila 44 4 6
;
run ;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Sep 2021 11:46:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/number-rows-from-1-to-3-only-on-criteria/m-p/766819#M243053</guid>
      <dc:creator>Nasser_DRMCP</dc:creator>
      <dc:date>2021-09-09T11:46:15Z</dc:date>
    </item>
    <item>
      <title>Re: number rows from 1 to 3 only on criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/number-rows-from-1-to-3-only-on-criteria/m-p/766821#M243055</link>
      <description>&lt;P&gt;hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;sorry for my question, I found this&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; want(&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;drop&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; = c);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; have;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; name ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; first.name &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; c=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; i_jour_sem ne i_sem &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; flag = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;else&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt; flag = sum(c, &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt; c = sum(c, &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; c = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; c = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;retain&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; c;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Sep 2021 11:50:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/number-rows-from-1-to-3-only-on-criteria/m-p/766821#M243055</guid>
      <dc:creator>Nasser_DRMCP</dc:creator>
      <dc:date>2021-09-09T11:50:10Z</dc:date>
    </item>
  </channel>
</rss>

