<?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 count the number of observations has variable value greater than the current value? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-the-number-of-observations-has-variable-value/m-p/446449#M112011</link>
    <description>&lt;P&gt;Thank you! works great!&lt;/P&gt;</description>
    <pubDate>Sat, 17 Mar 2018 15:01:40 GMT</pubDate>
    <dc:creator>cxterm</dc:creator>
    <dc:date>2018-03-17T15:01:40Z</dc:date>
    <item>
      <title>How to count the number of observations has variable value greater than the current value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-the-number-of-observations-has-variable-value/m-p/446328#M111962</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;Here is a sample dataset with variable A&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I want a cnt variable CNT like&amp;nbsp;&lt;/P&gt;&lt;P&gt;A &amp;nbsp; CNT&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(since there a 2 '2' just before the next '1')&amp;nbsp;&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(since there no '3' just before the next '2')&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; 3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(there are 3 '2' before the next '1')&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (there are 2 '3' before the next '2')&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How could I got the CNT? Any help?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Fri, 16 Mar 2018 20:12:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-count-the-number-of-observations-has-variable-value/m-p/446328#M111962</guid>
      <dc:creator>cxterm</dc:creator>
      <dc:date>2018-03-16T20:12:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of observations has variable value greater than the current value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-the-number-of-observations-has-variable-value/m-p/446413#M111995</link>
      <description>&lt;P&gt;You can do this counting with random access:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have nobs=nobs;
cnt = 0;
do point = _n_+1 to nobs until(_a = a);
    set have (rename=(a=_a)) point=point;
    cnt = cnt + (_a = a + 1);
    end;
drop _a;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 17 Mar 2018 04:20:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-count-the-number-of-observations-has-variable-value/m-p/446413#M111995</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-03-17T04:20:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of observations has variable value greater than the current value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-the-number-of-observations-has-variable-value/m-p/446447#M112009</link>
      <description>&lt;P&gt;Hash Table is my last resort .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input A;
cards;
1
2
2
1
1
2
2
3
3
2
1
;
data have;
 set have ;
 by a notsorted;
 group+first.a;
run;
data want;
 if _n_=1 then do;
  if 0 then set have(rename=(a=_a));
  declare hash h(dataset:'have(rename=(a=_a))',multidata:'y');
  h.definekey('group');
  h.definedata('_a');
  h.definedone();
 end;
set have;
by group;
count=0;
if last.group then do;
  _group=group+1;
  rc=h.find(key:_group);
  do while(rc=0);
    if _a=a+1 then count+1;
    rc=h.find_next(key:_group);
  end;
end;
drop _: rc group;
run;
proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 17 Mar 2018 14:23:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-count-the-number-of-observations-has-variable-value/m-p/446447#M112009</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-03-17T14:23:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of observations has variable value greater than the current value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-the-number-of-observations-has-variable-value/m-p/446449#M112011</link>
      <description>&lt;P&gt;Thank you! works great!&lt;/P&gt;</description>
      <pubDate>Sat, 17 Mar 2018 15:01:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-count-the-number-of-observations-has-variable-value/m-p/446449#M112011</guid>
      <dc:creator>cxterm</dc:creator>
      <dc:date>2018-03-17T15:01:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of observations has variable value greater than the current value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-the-number-of-observations-has-variable-value/m-p/446450#M112012</link>
      <description>&lt;P&gt;It also works although I select the way a little codings. Thank you!&lt;/P&gt;</description>
      <pubDate>Sat, 17 Mar 2018 15:03:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-count-the-number-of-observations-has-variable-value/m-p/446450#M112012</guid>
      <dc:creator>cxterm</dc:creator>
      <dc:date>2018-03-17T15:03:43Z</dc:date>
    </item>
  </channel>
</rss>

