<?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: Count records that contains specific text in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Count-records-that-contains-specific-text/m-p/127988#M34990</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for the quick reply linlin.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Exactly what I needed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, would you know a more efficient method to perform the count above?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 05 Mar 2013 23:03:41 GMT</pubDate>
    <dc:creator>nicnad</dc:creator>
    <dc:date>2013-03-05T23:03:41Z</dc:date>
    <item>
      <title>Count records that contains specific text</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-records-that-contains-specific-text/m-p/127986#M34988</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have the following SAS code. As of right now, it displays each variables from mylib.test table + variables count_gafi, count_sanction and count_person. How can I make sure to only display the variables count_gafi, count_sanction and count_person&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the code. Thank you for your help and time.&amp;nbsp; :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data work.ind14_15_16;&lt;BR /&gt;set mylib.test end=eof;&lt;BR /&gt;by objet;&lt;BR /&gt;retain count_gafi count_sanction count_person ;&lt;/P&gt;&lt;P&gt;switch = "n";&lt;/P&gt;&lt;P&gt;if _n_ eq 1 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count_gafi=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count_sanction=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count_person=0;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;if index(lowcase(strip(objet)),'bolivie')&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)),'équateur')&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)),'equateur')&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)),'éthiopie')&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)),'ethiopie')&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)),'indonésie')&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)),'indonesie')&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)),'kenya')&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)),'nigeria')&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)),'nigéria')&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)),'pakistan')&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)),'sao')&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)),'sri lanka')&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)),'thailand')&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)),'tailand')&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)),'turquie')&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)),'tanzanie')&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)),'viet')&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)),'yemen')&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)),'yémen')&amp;gt;0&amp;nbsp; then do;&lt;BR /&gt;count_gafi=count_gafi+1;&lt;BR /&gt;switch = "y";&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;if index(lowcase(strip(objet)),'bélarus')&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)),'belarus' )&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)),'corée du nord' )&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)),'rpdc' )&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)),'coree du nord')&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)),'ivoire'&amp;nbsp; )&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)),'congo' )&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)),'chine' )&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)), 'cuba'&amp;nbsp; )&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)),'érythrée' )&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)), 'erythree')&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)), 'iran'&amp;nbsp; )&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)),'iraq' )&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)), 'liberia'&amp;nbsp; )&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)),'libéria' )&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)),'libye'&amp;nbsp; )&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)),'myanmar' )&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)),'birmanie')&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)), 'somalie'&amp;nbsp; )&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)),'sierra' )&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)), 'soudan')&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)), 'syrie' )&amp;gt;0 or&lt;BR /&gt;index(lowcase(strip(objet)),'zimbabwe')&amp;gt;0 &lt;BR /&gt;then do;&lt;BR /&gt;count_sanction=count_sanction+1;&lt;BR /&gt;switch = "y";&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;if switch ="n" then do;&lt;BR /&gt;count_person = count_person + 1; /* If the record is not part of count_gafi or count_sanction, I want it to be part of count_person */&lt;BR /&gt;end;&lt;BR /&gt;if eof;&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Mar 2013 20:16:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-records-that-contains-specific-text/m-p/127986#M34988</guid>
      <dc:creator>nicnad</dc:creator>
      <dc:date>2013-03-05T20:16:07Z</dc:date>
    </item>
    <item>
      <title>Re: Count records that contains specific text</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-records-that-contains-specific-text/m-p/127987#M34989</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;changing&lt;/P&gt;&lt;P&gt;data work.ind14_15_16;&lt;/P&gt;&lt;P&gt;to&lt;/P&gt;&lt;P&gt;data work.ind14_15_16(keep=count_:);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Mar 2013 21:11:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-records-that-contains-specific-text/m-p/127987#M34989</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2013-03-05T21:11:06Z</dc:date>
    </item>
    <item>
      <title>Re: Count records that contains specific text</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-records-that-contains-specific-text/m-p/127988#M34990</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for the quick reply linlin.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Exactly what I needed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, would you know a more efficient method to perform the count above?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Mar 2013 23:03:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-records-that-contains-specific-text/m-p/127988#M34990</guid>
      <dc:creator>nicnad</dc:creator>
      <dc:date>2013-03-05T23:03:41Z</dc:date>
    </item>
    <item>
      <title>Re: Count records that contains specific text</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-records-that-contains-specific-text/m-p/127989#M34991</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't know. Sorry:smileysilly:!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Mar 2013 14:18:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-records-that-contains-specific-text/m-p/127989#M34991</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2013-03-06T14:18:40Z</dc:date>
    </item>
    <item>
      <title>Re: Count records that contains specific text</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-records-that-contains-specific-text/m-p/127990#M34992</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could improve the speed by reducing the number of function calls.&amp;nbsp; Try adding this statement:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;newvar = lowcase(strip(objet));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then refer to NEWVAR inside all the INDEX functions.&lt;/P&gt;&lt;P&gt;You could restrict the variables you read in on the SET statement:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;set mylib.test (keep=objet) end=eof;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;More complex, and possibly beyond your skill level, it appears your data are sorted by objet.&amp;nbsp; In that case, you could compute flags for the first observation for each value of objet.&amp;nbsp; The flags would indicate whether count_gafi or count_sanction should be incremented for that value of objet (and whether switch should be y or n).&amp;nbsp; Then all the remaining observations for the same value of objet could use the flags, instead of recomputing using a ton of functions for each observation that has the same value of objet.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Mar 2013 14:39:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-records-that-contains-specific-text/m-p/127990#M34992</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2013-03-06T14:39:19Z</dc:date>
    </item>
    <item>
      <title>Re: Count records that contains specific text</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-records-that-contains-specific-text/m-p/127991#M34993</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much for the recommandation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Mar 2013 15:18:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-records-that-contains-specific-text/m-p/127991#M34993</guid>
      <dc:creator>nicnad</dc:creator>
      <dc:date>2013-03-06T15:18:31Z</dc:date>
    </item>
  </channel>
</rss>

