<?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 how many times a surname appears in an email address in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-a-surname-appears-in-an-email-address/m-p/729210#M226901</link>
    <description>Hi Peter,&lt;BR /&gt;&lt;BR /&gt;This is almost perfect for what I need, so thank you for that!&lt;BR /&gt;&lt;BR /&gt;Is there a way to make the count a row-wise count, rather than a cumulative count? So, if I were to have say 100 rows, can I make the count the number of matches in each row?&lt;BR /&gt;&lt;BR /&gt;Many thanks,&lt;BR /&gt;Chris</description>
    <pubDate>Thu, 25 Mar 2021 19:35:41 GMT</pubDate>
    <dc:creator>ChrisJones92</dc:creator>
    <dc:date>2021-03-25T19:35:41Z</dc:date>
    <item>
      <title>Count how many times a surname appears in an email address</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-a-surname-appears-in-an-email-address/m-p/729167#M226889</link>
      <description>&lt;P&gt;Hi everyone, thanks in advance for the help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Essentially, I have an email address variable and a lastname variable in a SAS dataset. What I'm trying to do is count how many times the lastname appears in the email address for that row.&amp;nbsp;As an example:&lt;/P&gt;&lt;P&gt;Lastname: Smith&lt;/P&gt;&lt;P&gt;Email: Smithtestsmith@test.test&amp;nbsp;&lt;/P&gt;&lt;P&gt;Should return a count of two.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried fiddling with a rudimentary array, but I can only get it to count once. I'm sure this is possible, but I can't think how for the life of me. Both these variables are upper case, so case matching won't be an issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Sales_Te;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Sales;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;leng=length(lastname);&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; i=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;to&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; leng;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; substr(email,i,leng) = lastname &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; name=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&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;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;drop&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; leng;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Mar 2021 18:32:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-a-surname-appears-in-an-email-address/m-p/729167#M226889</guid>
      <dc:creator>ChrisJones92</dc:creator>
      <dc:date>2021-03-25T18:32:28Z</dc:date>
    </item>
    <item>
      <title>Re: Count how many times a surname appears in an email address</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-a-surname-appears-in-an-email-address/m-p/729171#M226891</link>
      <description>Sorry, leng in my array should be 'leng=length(email), but it still won't do what I need it to. Thanks</description>
      <pubDate>Thu, 25 Mar 2021 18:37:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-a-surname-appears-in-an-email-address/m-p/729171#M226891</guid>
      <dc:creator>ChrisJones92</dc:creator>
      <dc:date>2021-03-25T18:37:05Z</dc:date>
    </item>
    <item>
      <title>Re: Count how many times a surname appears in an email address</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-a-surname-appears-in-an-email-address/m-p/729174#M226892</link>
      <description>&lt;P&gt;See if this approach works for you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
s = "Smith";
m = "Smithtestsmith@test.test";

do i = 1 to length(m) - length(s);
   if lowcase(substr(m, i, length(s))) = lowcase(s) then count + 1;
end;

put count =;
 
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Mar 2021 18:41:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-a-surname-appears-in-an-email-address/m-p/729174#M226892</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-03-25T18:41:49Z</dc:date>
    </item>
    <item>
      <title>Re: Count how many times a surname appears in an email address</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-a-surname-appears-in-an-email-address/m-p/729179#M226895</link>
      <description>&lt;P&gt;Also:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   s = "Smith";
   m = "Smithtestsmith@test.test";
   count = count(m, s, 'i');
   put count =;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Mar 2021 18:49:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-a-surname-appears-in-an-email-address/m-p/729179#M226895</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-03-25T18:49:55Z</dc:date>
    </item>
    <item>
      <title>Re: Count how many times a surname appears in an email address</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-a-surname-appears-in-an-email-address/m-p/729210#M226901</link>
      <description>Hi Peter,&lt;BR /&gt;&lt;BR /&gt;This is almost perfect for what I need, so thank you for that!&lt;BR /&gt;&lt;BR /&gt;Is there a way to make the count a row-wise count, rather than a cumulative count? So, if I were to have say 100 rows, can I make the count the number of matches in each row?&lt;BR /&gt;&lt;BR /&gt;Many thanks,&lt;BR /&gt;Chris</description>
      <pubDate>Thu, 25 Mar 2021 19:35:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-a-surname-appears-in-an-email-address/m-p/729210#M226901</guid>
      <dc:creator>ChrisJones92</dc:creator>
      <dc:date>2021-03-25T19:35:41Z</dc:date>
    </item>
    <item>
      <title>Re: Count how many times a surname appears in an email address</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-a-surname-appears-in-an-email-address/m-p/729215#M226904</link>
      <description>&lt;LI-CODE lang="sas"&gt;data _null_;
s = "Smith";
m = "Smithtestsmith@test.test";

do i = 1 to length(m) - length(s);
   if lowcase(substr(m, i, length(s))) = lowcase(s) then count =sum(count, 1);
end;

put count =;
 
run;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code "then count+1" creates an implied Retain statement, which keeps the values across data step iteration boundaries. Using count = sum(count,1); instead adds 1 each time the statement is true but resets for each statement. If the condition is never true for a record the result will be missing. The Sum function only adds, or sums, non-missing values so does not have any oddities that + would have when count is undefined or missing such as the first time the condition is true.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Mar 2021 19:52:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-a-surname-appears-in-an-email-address/m-p/729215#M226904</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-25T19:52:47Z</dc:date>
    </item>
    <item>
      <title>Re: Count how many times a surname appears in an email address</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-a-surname-appears-in-an-email-address/m-p/729218#M226907</link>
      <description>Hi Ballardw,&lt;BR /&gt;&lt;BR /&gt;This is perfect and does exactly what I need it to! Huge thanks to both you and Peter for your help.&lt;BR /&gt;&lt;BR /&gt;Chris</description>
      <pubDate>Thu, 25 Mar 2021 19:58:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-a-surname-appears-in-an-email-address/m-p/729218#M226907</guid>
      <dc:creator>ChrisJones92</dc:creator>
      <dc:date>2021-03-25T19:58:30Z</dc:date>
    </item>
    <item>
      <title>Re: Count how many times a surname appears in an email address</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-a-surname-appears-in-an-email-address/m-p/729224#M226909</link>
      <description>&lt;P&gt;You could use regular expressions this way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
name = "Smith";
length dum $200;
do email = "Smithtestsmith@test.test", "test@test.test";
    id = prxParse(cats("s/",name,"//i"));
    call prxChange(id, -1, email, dum, len, trunc, nb);
    call prxFree(id);
    output;
    end;
drop dum id len trunc;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PGStats_0-1616702989574.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/56512iFBB6E3D2A700831F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="PGStats_0-1616702989574.png" alt="PGStats_0-1616702989574.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Mar 2021 20:11:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-a-surname-appears-in-an-email-address/m-p/729224#M226909</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2021-03-25T20:11:25Z</dc:date>
    </item>
  </channel>
</rss>

