<?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: Counting multiple substrings in one string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Counting-multiple-substrings-in-one-string/m-p/627118#M185039</link>
    <description>&lt;P&gt;Does your dataset look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dlm='|' dsd;
input String :$30. Substrings :$30.;
datalines;
Abc, def, jhi klm, abc,def|Abc, def, klm
Abc,jhi,zem,lmh,skj,abc|Abc,skj
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;?&lt;/P&gt;</description>
    <pubDate>Tue, 25 Feb 2020 07:56:19 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-02-25T07:56:19Z</dc:date>
    <item>
      <title>Counting multiple substrings in one string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-multiple-substrings-in-one-string/m-p/627115#M185036</link>
      <description>&lt;P&gt;Dear Colleagues,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi friends, I am new to SAS and would like someone’s favour to crack the code for my data manipulation before. Hi friends, I am new to SAS and would like someone’s favour to crack the code for my data manipulation before.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to count how many times multiple substrings (words) appear in a string.&amp;nbsp;&lt;SPAN&gt;For example in the string below, I would like to count how many times the substrings appear. i want the substrings to be counted regardless of the case (whether upper or lowwer)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;SPAN&gt;String&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;SPAN&gt;Substrings to be counted&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;SPAN&gt;Num_substrings&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;SPAN&gt;Abc, def, jhi klm, abc,def&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;SPAN&gt;Abc, def, klm&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;SPAN&gt;5&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;SPAN&gt;Abc,jhi,zem,lmh,skj,abc&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;SPAN&gt;Abc,skj&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;SPAN&gt;3&lt;/SPAN&gt;&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;Thanks a bunch.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dathan Byonaneby&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 07:43:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-multiple-substrings-in-one-string/m-p/627115#M185036</guid>
      <dc:creator>DathanMD</dc:creator>
      <dc:date>2020-02-25T07:43:28Z</dc:date>
    </item>
    <item>
      <title>Re: Counting multiple substrings in one string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-multiple-substrings-in-one-string/m-p/627118#M185039</link>
      <description>&lt;P&gt;Does your dataset look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dlm='|' dsd;
input String :$30. Substrings :$30.;
datalines;
Abc, def, jhi klm, abc,def|Abc, def, klm
Abc,jhi,zem,lmh,skj,abc|Abc,skj
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;?&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 07:56:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-multiple-substrings-in-one-string/m-p/627118#M185039</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-02-25T07:56:19Z</dc:date>
    </item>
    <item>
      <title>Re: Counting multiple substrings in one string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-multiple-substrings-in-one-string/m-p/627119#M185040</link>
      <description>The delimeter in the string is ',"&lt;BR /&gt;</description>
      <pubDate>Tue, 25 Feb 2020 07:59:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-multiple-substrings-in-one-string/m-p/627119#M185040</guid>
      <dc:creator>DathanMD</dc:creator>
      <dc:date>2020-02-25T07:59:00Z</dc:date>
    </item>
    <item>
      <title>Re: Counting multiple substrings in one string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-multiple-substrings-in-one-string/m-p/627121#M185042</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/294150"&gt;@DathanMD&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an approach to do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	infile datalines dlm="09"x;
	input String :$50. Substrings :$50.;
	datalines;
Abc, def, jhi klm, abc,def	Abc, def, klm
Abc,jhi,zem,lmh,skj,abc	Abc,skj
;
run;

proc sql noprint;
	select max(countw(Substrings)) into:total trimmed from have;
quit;

data want;
	set have;
	count=0;
	array _substring (&amp;amp;total) $50. _temporary_;
	array _nb_substring (&amp;amp;total) _temporary_;
	do i=1 to dim(_substring);
		_substring(i)=scan(Substrings,i,",");
		_nb_substring(i)=count(String, strip(_substring(i)),"i");
	end;
	count=sum(of _nb_substring(*));
	drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Capture d’écran 2020-02-25 à 09.18.59.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/36385iDC8D34EA02622599/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Capture d’écran 2020-02-25 à 09.18.59.png" alt="Capture d’écran 2020-02-25 à 09.18.59.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 08:20:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-multiple-substrings-in-one-string/m-p/627121#M185042</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-25T08:20:03Z</dc:date>
    </item>
    <item>
      <title>Re: Counting multiple substrings in one string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-multiple-substrings-in-one-string/m-p/627124#M185044</link>
      <description>&lt;P&gt;Look at the dataset created by my data step; does it look like the dataset you have?&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/294150"&gt;@DathanMD&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;The delimeter in the string is ',"&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 08:17:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-multiple-substrings-in-one-string/m-p/627124#M185044</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-02-25T08:17:08Z</dc:date>
    </item>
    <item>
      <title>Re: Counting multiple substrings in one string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-multiple-substrings-in-one-string/m-p/627129#M185045</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/294150"&gt;@DathanMD&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another approach could be the following one:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	infile datalines dlm="09"x;
	input String :$50. Substrings :$50.;
	datalines;
Abc, def, jhi klm, abc,def	Abc, def, klm
Abc,jhi,zem,lmh,skj,abc	Abc,skj
;
run;

data want;
	set have;
	count=0;
	do i=1 to countw(Substrings,",");
		count + count(String, strip(scan(Substrings,i,",")),"i");
	end;
	drop i;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Capture d’écran 2020-02-25 à 09.18.59.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/36386iB90F27B43F434DDF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Capture d’écran 2020-02-25 à 09.18.59.png" alt="Capture d’écran 2020-02-25 à 09.18.59.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 08:56:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-multiple-substrings-in-one-string/m-p/627129#M185045</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-25T08:56:55Z</dc:date>
    </item>
  </channel>
</rss>

