<?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 Count substring 'Id' number of times appeared in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Count-substring-Id-number-of-times-appeared/m-p/774484#M246163</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a data looks like this below. I would like to count number of times substring '&lt;EM&gt;&lt;STRONG&gt;Id&lt;/STRONG&gt;&lt;/EM&gt;' appeared in the variable Practise. I tried below code but it does not work, my code generates only 0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Raw Data:&lt;/STRONG&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Practise&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Id: John, Id: Kerstin, Name: sunny,&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Name: Kane, Id: Rohan&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Id: Ranson, Name: X_, Id: Stary&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Id:Ata, Name: Unknown, Id: Aka, Name, Unknown, Id: Prx&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Expected Result:&lt;/STRONG&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Practise&lt;/TD&gt;&lt;TD&gt;Id_Count&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Id: John, Id: Kerstin, Name: sunny,&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Name: Kane, Id: Rohan&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Id: Ranson, Name: X_, Id: Stary&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Id:Ata, Name: Unknown, Id: Aka, Name, Unknown, Id: Prx&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;My SAS code:&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data samp ;&lt;BR /&gt;set Clean;&lt;BR /&gt;&amp;nbsp; count_Id = count(Practice, 'Id:');&lt;BR /&gt;&amp;nbsp; &amp;nbsp;put count_Id;&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Fri, 15 Oct 2021 13:18:22 GMT</pubDate>
    <dc:creator>chapidi99</dc:creator>
    <dc:date>2021-10-15T13:18:22Z</dc:date>
    <item>
      <title>Count substring 'Id' number of times appeared</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-substring-Id-number-of-times-appeared/m-p/774484#M246163</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a data looks like this below. I would like to count number of times substring '&lt;EM&gt;&lt;STRONG&gt;Id&lt;/STRONG&gt;&lt;/EM&gt;' appeared in the variable Practise. I tried below code but it does not work, my code generates only 0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Raw Data:&lt;/STRONG&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Practise&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Id: John, Id: Kerstin, Name: sunny,&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Name: Kane, Id: Rohan&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Id: Ranson, Name: X_, Id: Stary&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Id:Ata, Name: Unknown, Id: Aka, Name, Unknown, Id: Prx&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Expected Result:&lt;/STRONG&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Practise&lt;/TD&gt;&lt;TD&gt;Id_Count&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Id: John, Id: Kerstin, Name: sunny,&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Name: Kane, Id: Rohan&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Id: Ranson, Name: X_, Id: Stary&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Id:Ata, Name: Unknown, Id: Aka, Name, Unknown, Id: Prx&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;My SAS code:&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data samp ;&lt;BR /&gt;set Clean;&lt;BR /&gt;&amp;nbsp; count_Id = count(Practice, 'Id:');&lt;BR /&gt;&amp;nbsp; &amp;nbsp;put count_Id;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Oct 2021 13:18:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-substring-Id-number-of-times-appeared/m-p/774484#M246163</guid>
      <dc:creator>chapidi99</dc:creator>
      <dc:date>2021-10-15T13:18:22Z</dc:date>
    </item>
    <item>
      <title>Re: Count substring 'Id' number of times appeared</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-substring-Id-number-of-times-appeared/m-p/774485#M246164</link>
      <description>Corrected code (Practise variable), but still doesn't work&lt;BR /&gt;&lt;BR /&gt;data samp ;&lt;BR /&gt;set Clean;&lt;BR /&gt;count_Id = count(Practise, 'Id:');&lt;BR /&gt;put count_Id;&lt;BR /&gt;run;</description>
      <pubDate>Fri, 15 Oct 2021 13:20:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-substring-Id-number-of-times-appeared/m-p/774485#M246164</guid>
      <dc:creator>chapidi99</dc:creator>
      <dc:date>2021-10-15T13:20:01Z</dc:date>
    </item>
    <item>
      <title>Re: Count substring 'Id' number of times appeared</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-substring-Id-number-of-times-appeared/m-p/774656#M246226</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/307587"&gt;@chapidi99&lt;/a&gt;&amp;nbsp;What doesn't work? Your code appears to return the expected result for your sample data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover dlm='|';
  input Practise :$100. count_expected;
  datalines;
Id: John, Id: Kerstin, Name: sunny,|2
Name: Kane, Id: Rohan|1
Id: Ranson, Name: X_, Id: Stary|2
Id:Ata, Name: Unknown, Id: Aka, Name, Unknown, Id: Prx|3
;

data want;
  set have;
  count_Id = count(Practise, 'Id:');
  count_derived_1=count(Practise,'id:','i');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1634364284017.png" style="width: 535px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/64774i1B148DF5967DCD1C/image-dimensions/535x107?v=v2" width="535" height="107" role="button" title="Patrick_0-1634364284017.png" alt="Patrick_0-1634364284017.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Oct 2021 06:04:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-substring-Id-number-of-times-appeared/m-p/774656#M246226</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-10-16T06:04:56Z</dc:date>
    </item>
    <item>
      <title>Re: Count substring 'Id' number of times appeared</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-substring-Id-number-of-times-appeared/m-p/774839#M246300</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;, thanks it works when I removed put statement.</description>
      <pubDate>Mon, 18 Oct 2021 07:57:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-substring-Id-number-of-times-appeared/m-p/774839#M246300</guid>
      <dc:creator>chapidi99</dc:creator>
      <dc:date>2021-10-18T07:57:58Z</dc:date>
    </item>
  </channel>
</rss>

