<?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 use IF THEN function to count on each observation separately in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-IF-THEN-function-to-count-on-each-observation/m-p/208364#M267216</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Hai,&lt;/P&gt;&lt;P&gt;I'm not sure I understand it.&lt;/P&gt;&lt;P&gt;Is the count missing can reset variables to 0 ?&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 18 Jun 2015 03:30:11 GMT</pubDate>
    <dc:creator>Noleen</dc:creator>
    <dc:date>2015-06-18T03:30:11Z</dc:date>
    <item>
      <title>How to use IF THEN function to count on each observation separately</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-IF-THEN-function-to-count-on-each-observation/m-p/208360#M267212</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I need to count how many numbers starting with '1' '2' '3's in each observation.&lt;/P&gt;&lt;P&gt;There are&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt; 700 variables and 50000 observations.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I use the following code, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt; set have;&lt;/P&gt;&lt;P&gt; array chars $ chars1-char700;&lt;/P&gt;&lt;P&gt; array counts counts1-counts3;&lt;/P&gt;&lt;P&gt; do over chars ;&lt;/P&gt;&lt;P&gt; if substr(chars,1,1)=1 then counts1+1;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt; if substr(chars,1,1)=2 then counts2+1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt; if substr(chars,1,1)=3 then counts3+1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;but the counts on each observation is adding on top of the result (counts) from the last observation.&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;How can I count them for each observation? (the counts need to star from 0 for each observation)&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;Many thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jun 2015 14:10:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-IF-THEN-function-to-count-on-each-observation/m-p/208360#M267212</guid>
      <dc:creator>Noleen</dc:creator>
      <dc:date>2015-06-17T14:10:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to use IF THEN function to count on each observation separately</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-IF-THEN-function-to-count-on-each-observation/m-p/208361#M267213</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do you only have 1,2,3? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To answer your initial question counts1+1 creates an implicit retain, change the counter to counts1=counts1+1 or explicitly set the variables to 0 at the beginning of each loop&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jun 2015 14:21:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-IF-THEN-function-to-count-on-each-observation/m-p/208361#M267213</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-06-17T14:21:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to use IF THEN function to count on each observation separately</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-IF-THEN-function-to-count-on-each-observation/m-p/208362#M267214</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;On top of Reeza's suggestions, you can also set counts missing for every data step iteration:&lt;/P&gt;&lt;P&gt;call missing (of counts(*)); Some simplification has also been suggested in the following code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;data&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; want;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;array&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; chars chars1-chars700;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;array&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; counts counts1-counts3;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;call&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; missing(of counts(*));&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;do&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;over&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; chars;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; counts(input(first(chars),&lt;/SPAN&gt;&lt;SPAN style="color: teal; background: white; font-family: 'Courier New';"&gt;&lt;STRONG&gt;1.&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;))+&lt;/SPAN&gt;&lt;SPAN style="color: teal; background: white; font-family: 'Courier New';"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;end&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: navy; background: white; font-family: 'Courier New';"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jun 2015 14:52:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-IF-THEN-function-to-count-on-each-observation/m-p/208362#M267214</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2015-06-17T14:52:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to use IF THEN function to count on each observation separately</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-IF-THEN-function-to-count-on-each-observation/m-p/208363#M267215</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Reeza, &lt;/P&gt;&lt;P&gt;I tried count1=count1+1, it doesn't count the number at all. I don't know why. Do I need to set count1=0 at the beginning?&lt;/P&gt;&lt;P&gt;BTW, how can I set counts back to 0 at the beginning of the loop?&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Jun 2015 03:12:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-IF-THEN-function-to-count-on-each-observation/m-p/208363#M267215</guid>
      <dc:creator>Noleen</dc:creator>
      <dc:date>2015-06-18T03:12:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to use IF THEN function to count on each observation separately</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-IF-THEN-function-to-count-on-each-observation/m-p/208364#M267216</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Hai,&lt;/P&gt;&lt;P&gt;I'm not sure I understand it.&lt;/P&gt;&lt;P&gt;Is the count missing can reset variables to 0 ?&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Jun 2015 03:30:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-IF-THEN-function-to-count-on-each-observation/m-p/208364#M267216</guid>
      <dc:creator>Noleen</dc:creator>
      <dc:date>2015-06-18T03:30:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to use IF THEN function to count on each observation separately</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-IF-THEN-function-to-count-on-each-observation/m-p/208365#M267217</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;data want;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;set have;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;array chars $ chars1-char700;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;array counts counts1-counts3;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;counts1=0;counts2=0;counts3=0;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;do over chars ;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;if substr(chars,1,1)=1 then counts1+1;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.3333330154419px; font-family: inherit;"&gt;if substr(chars,1,1)=2 then counts2+1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.3333330154419px; font-family: inherit;"&gt;if substr(chars,1,1)=3 then counts3+1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;end;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Jun 2015 04:48:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-IF-THEN-function-to-count-on-each-observation/m-p/208365#M267217</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-06-18T04:48:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to use IF THEN function to count on each observation separately</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-IF-THEN-function-to-count-on-each-observation/m-p/208366#M267218</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Reeza;&lt;/P&gt;&lt;P&gt;It still sum up the counts..&lt;/P&gt;&lt;P&gt;&lt;IMG alt="sas.png" class="jive-image" src="https://communities.sas.com/legacyfs/online/10889_sas.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Jun 2015 04:58:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-IF-THEN-function-to-count-on-each-observation/m-p/208366#M267218</guid>
      <dc:creator>Noleen</dc:creator>
      <dc:date>2015-06-18T04:58:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to use IF THEN function to count on each observation separately</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-IF-THEN-function-to-count-on-each-observation/m-p/208367#M267219</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Reeza,&lt;/P&gt;&lt;P&gt;I miss typed the name.&lt;/P&gt;&lt;P&gt;It works!! Thanks a lot!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Jun 2015 05:02:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-IF-THEN-function-to-count-on-each-observation/m-p/208367#M267219</guid>
      <dc:creator>Noleen</dc:creator>
      <dc:date>2015-06-18T05:02:58Z</dc:date>
    </item>
  </channel>
</rss>

