<?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: Characters Count in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Characters-Count/m-p/819967#M34799</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input mass $80.;
  datalines;
abcde1234&amp;amp;9&amp;amp;Y / defgh0987&amp;amp;2&amp;amp;N / attire1790&amp;amp;&amp;amp;4&amp;amp;Y
Daikin1290&amp;amp;6&amp;amp;Y / rets0987&amp;amp;2&amp;amp;N / attire1790&amp;amp;4&amp;amp;Y
;

data want;
  set have;
count1=0;count2=0;
do i=1 to countw(mass,'/');
  temp=scan(scan(mass,i,'/'),1,'&amp;amp;','k');
  if strip(temp)='&amp;amp;' then count1+1;
  if strip(temp)='&amp;amp;&amp;amp;' then count2+1;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 23 Jun 2022 12:47:39 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2022-06-23T12:47:39Z</dc:date>
    <item>
      <title>Characters Count</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Characters-Count/m-p/819876#M34795</link>
      <description>&lt;P&gt;Hi Everyone. I've a variable which has value like below. Here every part is seperated by / .&lt;/P&gt;&lt;PRE&gt;Data have;
Input Mass $30.;
datalines;
abcde1234&amp;amp;9&amp;amp;Y / defgh0987&amp;amp;2&amp;amp;N / attire1790&amp;amp;&amp;amp;4&amp;amp;Y
Daikin1290&amp;amp;6&amp;amp;Y / rets0987&amp;amp;2&amp;amp;N / attire1790&amp;amp;4&amp;amp;Y
;
run;&lt;/PRE&gt;&lt;PRE&gt;Required output;
Mass                                                     count1      count2 
abcde1234&amp;amp;9&amp;amp;Y / defgh0987&amp;amp;2&amp;amp;N / attire1790&amp;amp;&amp;amp;4&amp;amp;Y            2            1

Daikin1290&amp;amp;6&amp;amp;Y / rets0987&amp;amp;2&amp;amp;N / attire1790&amp;amp;4&amp;amp;Y             3            0&lt;/PRE&gt;&lt;P&gt;I require the count of &amp;amp; and &amp;amp;&amp;amp; followed by numeric in two different fields named count1, count2.&lt;/P&gt;&lt;P&gt;For example : abcde1234&amp;amp;9&amp;amp;Y in this part&amp;nbsp; the count1 is 1 and count2 is 0 ,because only one&amp;nbsp; &amp;amp; is before 9&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;defgh0987&amp;amp;2&amp;amp;N in this part the count1 is 1 and count2 is 0 , because&amp;nbsp; only one &amp;amp; is before 2.&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;attire1790&amp;amp;&amp;amp;4&amp;amp;Y in this part the count1 is 0 and count2 is 1, because there are 2 &amp;amp;'s before 4.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For your understanding purpose I differentiated them but it is a single value of Mass field. And also please do consider &amp;amp; and &amp;amp;&amp;amp; 's count as 1 . For 1 &amp;amp; the count is 1 and for &amp;amp;&amp;amp; the count is 1. Looking for some support. Thankyou!.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 03:12:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Characters-Count/m-p/819876#M34795</guid>
      <dc:creator>Vasundha</dc:creator>
      <dc:date>2022-06-23T03:12:43Z</dc:date>
    </item>
    <item>
      <title>Re: Characters Count</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Characters-Count/m-p/819887#M34796</link>
      <description>&lt;P&gt;Not sure if you want a separate observation per sub-string separated by forward slash or not. Below code just counts over the full string.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input mass $80.;
  datalines;
abcde1234&amp;amp;9&amp;amp;Y / defgh0987&amp;amp;2&amp;amp;N / attire1790&amp;amp;&amp;amp;4&amp;amp;Y
Daikin1290&amp;amp;6&amp;amp;Y / rets0987&amp;amp;2&amp;amp;N / attire1790&amp;amp;4&amp;amp;Y
;

data want;
  set have;
  /* create variable _mass with same length as mass */
  if 0 then _mass=mass;
  /* replace all digits with 1 */
  _mass=prxchange('s/\d+/1/oi',-1,strip(mass));
  /* count substrings */
  count2=count(_mass,'&amp;amp;&amp;amp;1');
  count1=count(_mass,'&amp;amp;1')-count2;
  drop _mass;
run;

proc print data=want;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1655964129978.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72630iA24FC400023B78F5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1655964129978.png" alt="Patrick_0-1655964129978.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 06:02:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Characters-Count/m-p/819887#M34796</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-06-23T06:02:17Z</dc:date>
    </item>
    <item>
      <title>Re: Characters Count</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Characters-Count/m-p/819889#M34797</link>
      <description>&lt;P&gt;This is exactly what I require. Please fill your heart heartily thanked.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 06:27:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Characters-Count/m-p/819889#M34797</guid>
      <dc:creator>Vasundha</dc:creator>
      <dc:date>2022-06-23T06:27:06Z</dc:date>
    </item>
    <item>
      <title>Re: Characters Count</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Characters-Count/m-p/819959#M34798</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/420851"&gt;@Vasundha&lt;/a&gt;&amp;nbsp;If you're happy with a proposed answer then mark this answer as solution. This not only marks the question as answered, it also "rewards" the person who provided the most helpful answer.&lt;/P&gt;
&lt;P&gt;Also don't hesitate to "like" other answers that you consider helpful.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 12:13:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Characters-Count/m-p/819959#M34798</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-06-23T12:13:09Z</dc:date>
    </item>
    <item>
      <title>Re: Characters Count</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Characters-Count/m-p/819967#M34799</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input mass $80.;
  datalines;
abcde1234&amp;amp;9&amp;amp;Y / defgh0987&amp;amp;2&amp;amp;N / attire1790&amp;amp;&amp;amp;4&amp;amp;Y
Daikin1290&amp;amp;6&amp;amp;Y / rets0987&amp;amp;2&amp;amp;N / attire1790&amp;amp;4&amp;amp;Y
;

data want;
  set have;
count1=0;count2=0;
do i=1 to countw(mass,'/');
  temp=scan(scan(mass,i,'/'),1,'&amp;amp;','k');
  if strip(temp)='&amp;amp;' then count1+1;
  if strip(temp)='&amp;amp;&amp;amp;' then count2+1;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Jun 2022 12:47:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Characters-Count/m-p/819967#M34799</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-06-23T12:47:39Z</dc:date>
    </item>
  </channel>
</rss>

