<?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: Trouble with count variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Trouble-with-count-variable/m-p/329673#M271830</link>
    <description>&lt;P&gt;If you want to increment count when x doesn't equal either missing or 0, then you're boolean logic is wrong. Try:&lt;/P&gt;
&lt;PRE&gt;DATA WORK.A;
SET B;
 
IF (X NE . and X NE 0)
THEN
DO;
 COUNT + 1;
END;
 
RUN;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HTH,&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 03 Feb 2017 03:54:17 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2017-02-03T03:54:17Z</dc:date>
    <item>
      <title>Trouble with count variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trouble-with-count-variable/m-p/329671#M271829</link>
      <description>&lt;P&gt;Hi, I am new in SAS and trying to do a basic count varible but after it count the first observation the count variable remains the same.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;DATA WORK.A;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;SET B;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;IF (X NE&amp;nbsp;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; OR X NE &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&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;THEN&lt;/P&gt;&lt;P&gt;DO;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;COUNT + &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&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;END;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Feb 2017 03:37:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trouble-with-count-variable/m-p/329671#M271829</guid>
      <dc:creator>edu</dc:creator>
      <dc:date>2017-02-03T03:37:07Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble with count variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trouble-with-count-variable/m-p/329673#M271830</link>
      <description>&lt;P&gt;If you want to increment count when x doesn't equal either missing or 0, then you're boolean logic is wrong. Try:&lt;/P&gt;
&lt;PRE&gt;DATA WORK.A;
SET B;
 
IF (X NE . and X NE 0)
THEN
DO;
 COUNT + 1;
END;
 
RUN;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HTH,&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Feb 2017 03:54:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trouble-with-count-variable/m-p/329673#M271830</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-03T03:54:17Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble with count variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trouble-with-count-variable/m-p/329719#M271831</link>
      <description>&lt;P&gt;If you already have a variable count in dataset b, this won't work, as the values read from the dataset will override your increment.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Feb 2017 09:06:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trouble-with-count-variable/m-p/329719#M271831</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-02-03T09:06:35Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble with count variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trouble-with-count-variable/m-p/329738#M271832</link>
      <description>&lt;P&gt;Tip 1, make your code nice and readble, this is more important than what it actually does in most cases:&lt;/P&gt;
&lt;PRE&gt;data work.a; 
  set b;
  if _n_=1 then count=0;
  count=count + ifn(x not in (.,0),1,0);
run;
  
&lt;/PRE&gt;
&lt;P&gt;Note the consistent casing, and the indentations, and also the use of the code window (either {i} above your post or the SAS one). &amp;nbsp;I would also avoid naming datasets a and b.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tip 2, post test data in the form of a datastep:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Remember we cannot see your computer, we don't know what your data looks like.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Feb 2017 09:50:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trouble-with-count-variable/m-p/329738#M271832</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-02-03T09:50:30Z</dc:date>
    </item>
  </channel>
</rss>

