<?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: how to creat count with in the range in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-sequence-number-and-count-number/m-p/723585#M224551</link>
    <description>I updated raw data.</description>
    <pubDate>Thu, 04 Mar 2021 19:42:45 GMT</pubDate>
    <dc:creator>thanikondharish</dc:creator>
    <dc:date>2021-03-04T19:42:45Z</dc:date>
    <item>
      <title>how to create sequence number and count number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-sequence-number-and-count-number/m-p/723449#M224497</link>
      <description>&lt;P&gt;data sample;&lt;BR /&gt;input id type $ date mark $ stagen class $;&lt;BR /&gt;informat date yymmdd10.;&lt;BR /&gt;format date yymmdd10.;&lt;BR /&gt;cards;&lt;BR /&gt;1001 aaa 2020-11-01 . 1 class1&lt;BR /&gt;1001 aaa 2020-11-01 . 2 class1&lt;BR /&gt;1001 aaa 2020-11-01 . 3 class1&lt;BR /&gt;1001 aaa 2020-11-01 first 4 class1&lt;BR /&gt;1001 aaa 2020-11-01 . 9 class1&lt;BR /&gt;1001 aaa 2020-11-01 . 9 class1&lt;BR /&gt;1001 aaa 2020-11-01 last 8 class1&lt;/P&gt;
&lt;P&gt;1001 aaa 2020-11-01 . 1 class2&lt;BR /&gt;1001 aaa 2020-11-01 . 2 class2&lt;BR /&gt;1001 aaa 2020-11-01 . 3 class2&lt;BR /&gt;1001 aaa 2020-11-01 first 4 class2&lt;BR /&gt;1001 aaa 2020-11-01 . 9 class2&lt;BR /&gt;1001 aaa 2020-11-01 . 9 class2&lt;BR /&gt;1001 aaa 2020-11-01 last 8 class2&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;how to create sequence number between first and last values in mark variable and how to count stagen='9'&lt;/P&gt;
&lt;P&gt;for your reference see below outupt&lt;/P&gt;
&lt;P&gt;&amp;nbsp; id&amp;nbsp; &amp;nbsp; &amp;nbsp;type&amp;nbsp; &amp;nbsp;date&amp;nbsp; &amp;nbsp; mark&amp;nbsp; stagen class&amp;nbsp; &amp;nbsp; seq&amp;nbsp; &amp;nbsp; &amp;nbsp; state9(count)&lt;/P&gt;
&lt;P&gt;1001 aaa 2020-11-01 .&amp;nbsp; &amp;nbsp; &amp;nbsp; 1 class1&lt;BR /&gt;1001 aaa 2020-11-01 .&amp;nbsp; &amp;nbsp; &amp;nbsp; 2 class1&lt;BR /&gt;1001 aaa 2020-11-01 .&amp;nbsp; &amp;nbsp; &amp;nbsp;3 class1&lt;BR /&gt;1001 aaa 2020-11-01 first 4 class1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&lt;BR /&gt;1001 aaa 2020-11-01 .&amp;nbsp; &amp;nbsp; &amp;nbsp;9 class1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;BR /&gt;1001 aaa 2020-11-01 .&amp;nbsp; &amp;nbsp; &amp;nbsp;9 class1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;BR /&gt;1001 aaa 2020-11-01 last 8 class1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;7&lt;/P&gt;
&lt;P&gt;1001 aaa 2020-11-01 .&amp;nbsp; &amp;nbsp; &amp;nbsp; 1 class2&lt;BR /&gt;1001 aaa 2020-11-01 .&amp;nbsp; &amp;nbsp; &amp;nbsp; 2 class2&lt;BR /&gt;1001 aaa 2020-11-01 .&amp;nbsp; &amp;nbsp; &amp;nbsp;3 class2&lt;BR /&gt;1001 aaa 2020-11-01 first 4 class2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&lt;BR /&gt;1001 aaa 2020-11-01 .&amp;nbsp; &amp;nbsp; &amp;nbsp;9 class2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;BR /&gt;1001 aaa 2020-11-01 .&amp;nbsp; &amp;nbsp; &amp;nbsp;9 class2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;BR /&gt;1001 aaa 2020-11-01 last 8 class2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7&lt;/P&gt;
&lt;P&gt;in above output between seq 4 and 7 there are state=9 two records are there these count reflect next&lt;/P&gt;
&lt;P&gt;column count=2&lt;/P&gt;
&lt;P&gt;by variables(id,type,class)&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 15:25:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-sequence-number-and-count-number/m-p/723449#M224497</guid>
      <dc:creator>thanikondharish</dc:creator>
      <dc:date>2021-03-04T15:25:01Z</dc:date>
    </item>
    <item>
      <title>Re: how to create sequence number and count number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-sequence-number-and-count-number/m-p/723454#M224498</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;how to count state='9'&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;There is no variable named STATE in your input data.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Please include code in a code box by clicking on the "little running man" icon and pasting your code into that box. That will help all of us.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 13:51:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-sequence-number-and-count-number/m-p/723454#M224498</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-03-04T13:51:41Z</dc:date>
    </item>
    <item>
      <title>Re: how to create sequence number and count number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-sequence-number-and-count-number/m-p/723456#M224499</link>
      <description>&lt;P&gt;What is your group?&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;id&lt;/LI&gt;
&lt;LI&gt;id and type&lt;/LI&gt;
&lt;LI&gt;id, type and date&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;?&lt;/P&gt;
&lt;P&gt;You want the count of 9s in those observations that have stagen = 9; do you want the whole count of 9s within a group (see above), or count only successive 9s?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Oh yes, and please post your code in proper manner, it won't make your head explode. Promised.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 13:54:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-sequence-number-and-count-number/m-p/723456#M224499</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-03-04T13:54:41Z</dc:date>
    </item>
    <item>
      <title>Re: how to create sequence number and count number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-sequence-number-and-count-number/m-p/723458#M224501</link>
      <description>state=9 is nothing but stagen=9&lt;BR /&gt;spelling mistake&lt;BR /&gt;</description>
      <pubDate>Thu, 04 Mar 2021 13:54:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-sequence-number-and-count-number/m-p/723458#M224501</guid>
      <dc:creator>thanikondharish</dc:creator>
      <dc:date>2021-03-04T13:54:45Z</dc:date>
    </item>
    <item>
      <title>Re: how to create sequence number and count number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-sequence-number-and-count-number/m-p/723459#M224502</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Please include code in a code box by clicking on the "little running man" icon and pasting your code into that box. That will help all of us.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 13:57:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-sequence-number-and-count-number/m-p/723459#M224502</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-03-04T13:57:44Z</dc:date>
    </item>
    <item>
      <title>Re: how to create sequence number and count number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-sequence-number-and-count-number/m-p/723460#M224503</link>
      <description>by id type&lt;BR /&gt;</description>
      <pubDate>Thu, 04 Mar 2021 13:57:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-sequence-number-and-count-number/m-p/723460#M224503</guid>
      <dc:creator>thanikondharish</dc:creator>
      <dc:date>2021-03-04T13:57:45Z</dc:date>
    </item>
    <item>
      <title>Re: how to create sequence number and count number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-sequence-number-and-count-number/m-p/723468#M224507</link>
      <description>&lt;P&gt;This code creates your expected result:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id type $ date mark $ stagen class $;
informat date yymmdd10.;
format date yymmdd10.;
cards;
1001 aaa 2020-11-01 . 1 class1
1001 aaa 2020-11-01 . 2 class1
1001 aaa 2020-11-01 . 3 class1
1001 aaa 2020-11-01 first 4 class1
1001 aaa 2020-11-01 . 9 class1
1001 aaa 2020-11-01 . 9 class1
1001 aaa 2020-11-01 last 8 class1
;

data want;
do until (last.type);
  set have;
  by id type;
  count9 = sum(count9,(stagen = 9));
end;
do until (last.type);
  set have;
  by id type;
  if mark = "first"
  then seq = stagen;
  else if seq ne . then seq = seq + 1;
  state9 = ifn(stagen = 9,count9,.);
  output;
end;
drop count9;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Mar 2021 14:10:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-sequence-number-and-count-number/m-p/723468#M224507</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-03-04T14:10:14Z</dc:date>
    </item>
    <item>
      <title>how to creat count with in the range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-sequence-number-and-count-number/m-p/723540#M224549</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;data have;
input id type $ date mark $ stagen class $;
informat date yymmdd10.;
format date yymmdd10.;
cards;
1001 aaa 2020-11-01 . 1 class1
1001 aaa 2020-11-01 . 2 class1
1001 aaa 2020-11-01 . 3 class1
1001 aaa 2020-11-01 first 4 class1
1001 aaa 2020-11-01 . 9 class1
1001 aaa 2020-11-01 . 9 class1
1001 aaa 2020-11-01 last 8 class1&lt;BR /&gt;1001 aaa 2020-11-01 . 9 class1&lt;BR /&gt;1001 aaa 2020-11-01 . 1 class2
1001 aaa 2020-11-01 . 2 class2
1001 aaa 2020-11-01 . 3 class2
1001 aaa 2020-11-01 first 4 class2
1001 aaa 2020-11-01 . 9 class2
1001 aaa 2020-11-01 . 9 class2&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE&gt;1001 aaa 2020-11-01 . 9 class2
1001 aaa 2020-11-01 last 8 class2&lt;BR /&gt;1001 aaa 2020-11-01 . 9 class2&lt;BR /&gt;1001 aaa 2020-11-01 . 9 class2&lt;BR /&gt;1001 aaa 2020-11-01 . 9 class2&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;I&amp;nbsp;have&amp;nbsp;one&amp;nbsp;dataset&amp;nbsp;like&amp;nbsp;above&amp;nbsp;how&amp;nbsp;to&amp;nbsp;get&amp;nbsp;output with count column&amp;nbsp;like&amp;nbsp;below&amp;nbsp;dataset?&lt;BR /&gt;Your&amp;nbsp;ref:&lt;BR /&gt;&lt;BR /&gt;id  type date    mark stagen class   count&lt;BR /&gt;1001 aaa 2020-11-01 . 1 class1
1001 aaa 2020-11-01 . 2 class1
1001 aaa 2020-11-01 . 3 class1
1001 aaa 2020-11-01 first 4 class1
1001 aaa 2020-11-01 . 9 class1         2
1001 aaa 2020-11-01 . 9 class1         2
1001 aaa 2020-11-01 last 8 class1&lt;BR /&gt;1001 aaa 2020-11-01 . 9 class1&lt;BR /&gt;1001 aaa 2020-11-01 . 1 class2
1001 aaa 2020-11-01 . 2 class2
1001 aaa 2020-11-01 . 3 class2
1001 aaa 2020-11-01 first 4 class2
1001 aaa 2020-11-01 . 9 class2        3
1001 aaa 2020-11-01 . 9 class2        3&lt;BR /&gt;1001 aaa 2020-11-01 . 9 class2        3
1001 aaa 2020-11-01 last 8 class2&lt;BR /&gt;1001 aaa 2020-11-01 . 9 class2&lt;BR /&gt;1001 aaa 2020-11-01 . 9 class2&lt;BR /&gt;1001 aaa 2020-11-01 . 9 class2&lt;BR /&gt;&lt;BR /&gt;Note:&amp;nbsp;between&amp;nbsp;mark='first'&amp;nbsp;&amp;nbsp;and&amp;nbsp;mark='last'&amp;nbsp;there&amp;nbsp;are&amp;nbsp;stagen=9&amp;nbsp;related&amp;nbsp;records&amp;nbsp;there.&lt;BR /&gt;How&amp;nbsp;to&amp;nbsp;take&amp;nbsp;those&amp;nbsp;count&amp;nbsp;like&amp;nbsp;see&amp;nbsp;above&amp;nbsp;output&amp;nbsp;dataset&lt;BR /&gt;by&amp;nbsp;variables&amp;nbsp;are&amp;nbsp;id,type,class&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 19:41:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-sequence-number-and-count-number/m-p/723540#M224549</guid>
      <dc:creator>thanikondharish</dc:creator>
      <dc:date>2021-03-04T19:41:17Z</dc:date>
    </item>
    <item>
      <title>Re: how to creat count with in the range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-sequence-number-and-count-number/m-p/723583#M224550</link>
      <description>&lt;P&gt;Your WANT dataset does not match your HAVE dataset.&amp;nbsp; The second pair of&amp;nbsp; &amp;nbsp;"first" ... "last" records has 3 intermediate records in WANT, but only 2 in HAVE.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 19:27:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-sequence-number-and-count-number/m-p/723583#M224550</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-03-04T19:27:08Z</dc:date>
    </item>
    <item>
      <title>Re: how to creat count with in the range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-sequence-number-and-count-number/m-p/723585#M224551</link>
      <description>I updated raw data.</description>
      <pubDate>Thu, 04 Mar 2021 19:42:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-sequence-number-and-count-number/m-p/723585#M224551</guid>
      <dc:creator>thanikondharish</dc:creator>
      <dc:date>2021-03-04T19:42:45Z</dc:date>
    </item>
    <item>
      <title>Re: how to creat count with in the range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-sequence-number-and-count-number/m-p/723591#M224552</link>
      <description>&lt;P&gt;I merged this into your previous thread concerning the same issue.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 19:55:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-sequence-number-and-count-number/m-p/723591#M224552</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-03-04T19:55:57Z</dc:date>
    </item>
    <item>
      <title>Re: how to create sequence number and count number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-sequence-number-and-count-number/m-p/723593#M224553</link>
      <description>&lt;P&gt;Thank you for providing sample data in a working DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id type $ date mark $ stagen class $;
  informat date yymmdd10.;
  format date yymmdd10.;
cards;
1001 aaa 2020-11-01 . 1 class1
1001 aaa 2020-11-01 . 2 class1
1001 aaa 2020-11-01 . 3 class1
1001 aaa 2020-11-01 first 4 class1
1001 aaa 2020-11-01 . 9 class1
1001 aaa 2020-11-01 . 9 class1
1001 aaa 2020-11-01 last 8 class1
1001 aaa 2020-11-01 . 9 class1
1001 aaa 2020-11-01 . 1 class2
1001 aaa 2020-11-01 . 2 class2
1001 aaa 2020-11-01 . 3 class2
1001 aaa 2020-11-01 first 4 class2
1001 aaa 2020-11-01 . 9 class2
1001 aaa 2020-11-01 . 9 class2
1001 aaa 2020-11-01 . 9 class2
1001 aaa 2020-11-01 last 8 class2
1001 aaa 2020-11-01 . 9 class2
1001 aaa 2020-11-01 . 9 class2
1001 aaa 2020-11-01 . 9 class2
data want (drop=_: i);
  /*read and count every record until "last" */
  do _n=1 by 1 until (mark='last    ' or last.type);
    set have;
    by id type;
    if mark='first' then _nfirst=_n; /*Note position of "first"*/
  end;

  /* Reread, recount, and output the same records */
  do i=1 to _n;
    set have;
    if _nfirst=. or i&amp;lt;=_nfirst or i=_n then count=. ;
    else count=(_n-_nfirst-1);
    output;
  end;
run;
  
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Mar 2021 19:58:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-sequence-number-and-count-number/m-p/723593#M224553</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-03-04T19:58:10Z</dc:date>
    </item>
    <item>
      <title>Re: how to creat count with in the range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-sequence-number-and-count-number/m-p/723594#M224554</link>
      <description>In 15 row entire record is space&lt;BR /&gt;We can remove&lt;BR /&gt;</description>
      <pubDate>Thu, 04 Mar 2021 19:58:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-sequence-number-and-count-number/m-p/723594#M224554</guid>
      <dc:creator>thanikondharish</dc:creator>
      <dc:date>2021-03-04T19:58:45Z</dc:date>
    </item>
  </channel>
</rss>

