<?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: RE: counting by two grouping variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/RE-counting-by-two-grouping-variables/m-p/229308#M41493</link>
    <description>&lt;P&gt;Can you think of any occurence where "ne" could be misinterpreted? &amp;nbsp;^ is power in most maths, and can be an escape char etc. &amp;nbsp;Personally I find the ne to be more readable, and that is my principal aim in programming.&lt;/P&gt;</description>
    <pubDate>Fri, 09 Oct 2015 15:02:15 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2015-10-09T15:02:15Z</dc:date>
    <item>
      <title>RE: counting by two grouping variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RE-counting-by-two-grouping-variables/m-p/229286#M41486</link>
      <description>&lt;P&gt;Hi....I am trying to do a count by two grouping variables and would like it to rest to a count of 1 when a new "Numb" occurs and not after a new "New_Dos" occurs. I am using&amp;nbsp;a Data Step that generates the following output ( highlighted the counts =1 and should be 2):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt; NEW;&lt;/P&gt;
&lt;P&gt;SET NEW;&lt;/P&gt;
&lt;P&gt;BY NUMB NEW_DOS;&lt;/P&gt;
&lt;P&gt;COUNT=&lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;IF NUMB = LAG(NUMB) AND NEW_DOS ^= LAG(NEW_DOS) THEN DO;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; COUNT=COUNT + &lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&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;&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;00816132&lt;/TD&gt;
&lt;TD&gt;G&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;00816132&lt;/TD&gt;
&lt;TD&gt;W / W&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;01914537&lt;/TD&gt;
&lt;TD&gt;ML&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Oct 2015 13:55:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RE-counting-by-two-grouping-variables/m-p/229286#M41486</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2015-10-09T13:55:31Z</dc:date>
    </item>
    <item>
      <title>Re: RE: counting by two grouping variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RE-counting-by-two-grouping-variables/m-p/229297#M41488</link>
      <description>&lt;P&gt;To reset your variable on numb, then just do:&lt;/P&gt;
&lt;PRE&gt;data new;
  set new;
  by numb new_dos;
  if first.num then count=1;
  if numb=lag(numb) and new_dos ne lag(new_dos) then do;
    count=count+1;
  end;
run;&lt;/PRE&gt;
&lt;P&gt;Do note the updates I have made to the code, not using all uppercase, and using ne rather than ^=.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Oct 2015 14:25:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RE-counting-by-two-grouping-variables/m-p/229297#M41488</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-10-09T14:25:55Z</dc:date>
    </item>
    <item>
      <title>Re: RE: counting by two grouping variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RE-counting-by-two-grouping-variables/m-p/229302#M41490</link>
      <description>&lt;P&gt;Why is ne preferred to ^= ???&lt;/P&gt;</description>
      <pubDate>Fri, 09 Oct 2015 14:39:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RE-counting-by-two-grouping-variables/m-p/229302#M41490</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2015-10-09T14:39:37Z</dc:date>
    </item>
    <item>
      <title>Re: RE: counting by two grouping variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RE-counting-by-two-grouping-variables/m-p/229303#M41491</link>
      <description>&lt;P&gt;Hi RW9....Thanks for your help. I tried it and I get a 1 for the first Numb ( as from the first If Statement) and all the rest are empty blanks...&lt;/P&gt;</description>
      <pubDate>Fri, 09 Oct 2015 14:43:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RE-counting-by-two-grouping-variables/m-p/229303#M41491</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2015-10-09T14:43:50Z</dc:date>
    </item>
    <item>
      <title>Re: RE: counting by two grouping variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RE-counting-by-two-grouping-variables/m-p/229305#M41492</link>
      <description>&lt;P&gt;Ah, pop a retain in then:&lt;/P&gt;
&lt;PRE&gt;data new;
  set new;
  by numb new_dos;
  retain count;
  if first.num then count=1;
  if numb=lag(numb) and new_dos ne lag(new_dos) then do;
    count=count+1;
  end;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Oct 2015 15:00:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RE-counting-by-two-grouping-variables/m-p/229305#M41492</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-10-09T15:00:02Z</dc:date>
    </item>
    <item>
      <title>Re: RE: counting by two grouping variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RE-counting-by-two-grouping-variables/m-p/229308#M41493</link>
      <description>&lt;P&gt;Can you think of any occurence where "ne" could be misinterpreted? &amp;nbsp;^ is power in most maths, and can be an escape char etc. &amp;nbsp;Personally I find the ne to be more readable, and that is my principal aim in programming.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Oct 2015 15:02:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RE-counting-by-two-grouping-variables/m-p/229308#M41493</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-10-09T15:02:15Z</dc:date>
    </item>
    <item>
      <title>Re: RE: counting by two grouping variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RE-counting-by-two-grouping-variables/m-p/229310#M41494</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;Can you think of any occurence where "ne" could be misinterpreted?&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;No, I can't. Please enlighten me.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Oct 2015 15:07:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RE-counting-by-two-grouping-variables/m-p/229310#M41494</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2015-10-09T15:07:19Z</dc:date>
    </item>
    <item>
      <title>Re: RE: counting by two grouping variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RE-counting-by-two-grouping-variables/m-p/229314#M41495</link>
      <description>&lt;P&gt;Thats my point, ne reads easier, and isn't used for anything else.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Oct 2015 15:21:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RE-counting-by-two-grouping-variables/m-p/229314#M41495</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-10-09T15:21:27Z</dc:date>
    </item>
    <item>
      <title>Re: RE: counting by two grouping variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RE-counting-by-two-grouping-variables/m-p/229328#M41501</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;ne reads easier and isn't used for anything else.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;My opinion is different. I have no problems seeing ^= in code and interpreting it or judging it to be readable.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Oct 2015 16:15:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RE-counting-by-two-grouping-variables/m-p/229328#M41501</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2015-10-09T16:15:10Z</dc:date>
    </item>
    <item>
      <title>Re: RE: counting by two grouping variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RE-counting-by-two-grouping-variables/m-p/229330#M41502</link>
      <description>&lt;P&gt;Not to thread hijack but typos like =^ do not cause an error whereas using "en" instead of "ne" will:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data _null_;
input x y;
if x =^ y then put "is this expected for " x= y=;
datalines;
0 0
0 1
3 5
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Oct 2015 16:25:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RE-counting-by-two-grouping-variables/m-p/229330#M41502</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-10-09T16:25:22Z</dc:date>
    </item>
    <item>
      <title>Re: RE: counting by two grouping variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/RE-counting-by-two-grouping-variables/m-p/229352#M41507</link>
      <description>&lt;P&gt;Hi, this also works (lot less SAS code)&amp;nbsp;...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data y;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;set x;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;by num newdos;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;newcount + first.newdos - first.num*newcount;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;take a look at ... &lt;EM&gt;&lt;STRONG&gt;Tips:Between and Within Group Counters&lt;/STRONG&gt;&lt;/EM&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&lt;A href="http://www.sascommunity.org/wiki/Tips:Between_and_Within_Group_Counters" target="_blank"&gt;http://www.sascommunity.org/wiki/Tips:Between_and_Within_Group_Counters&lt;/A&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Oct 2015 21:43:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/RE-counting-by-two-grouping-variables/m-p/229352#M41507</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2015-10-10T21:43:57Z</dc:date>
    </item>
  </channel>
</rss>

