<?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: How to sum a string variable until you reach a certain character in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648706#M194380</link>
    <description>Worked like a charm, thank you!</description>
    <pubDate>Mon, 18 May 2020 23:18:48 GMT</pubDate>
    <dc:creator>silversta</dc:creator>
    <dc:date>2020-05-18T23:18:48Z</dc:date>
    <item>
      <title>How to sum a string variable until you reach a certain character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648647#M194350</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am attempting to create a variable in my data that is the sum of the characters in a string (comprised of 0s and 1s). The code below does sum the 1s in the string, but I'm not sure how to manipulate it to provide the information that I'm looking for. For those whose strings start with 1s and change to 0s, that is ok. For those whose strings start with 0, regardless of the 1s that may follow, those need to be set to 0. Lastly, for those whose strings have 0s in the middle of the 1s, I need to only sum the 1s before it hits the 0. I apologize if this seems confusing and have tried to provide an illustration below of the string and the sum that I would like to calculate. Any help would be most appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;x_all &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; &amp;nbsp; &amp;nbsp; &amp;nbsp; sum that code below calculates &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;sum that I want&lt;/P&gt;&lt;P&gt;1111111000000 &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; &amp;nbsp;6 &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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6 &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;0000001111111 &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; &amp;nbsp;7 &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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1111000111111 &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; &amp;nbsp;10 &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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want (drop = i );&lt;BR /&gt;set have;&lt;BR /&gt;x_total=0;&lt;BR /&gt;do i=1 to length(x_all);&lt;BR /&gt;x_total+input(substr(x_all,i,1),1.);&lt;BR /&gt;end;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 18 May 2020 18:32:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648647#M194350</guid>
      <dc:creator>silversta</dc:creator>
      <dc:date>2020-05-18T18:32:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum a string variable until you reach a certain character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648653#M194352</link>
      <description>&lt;P&gt;Use a do while:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop = i );
set have;
x_total = 0;
i = 1;
do while (substr(x_all,i,1) = '1' and i le length(x_all));
  x_total + 1;
  i + 1;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 May 2020 18:44:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648653#M194352</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-18T18:44:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum a string variable until you reach a certain character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648657#M194354</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/311492"&gt;@silversta&lt;/a&gt;&amp;nbsp; If I understand you correctly, it's a simple boolean expression.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input x_all :$20.;*                                 sum that code below calculates        sum that I want;
cards;
1111111000000                            6                                                   6                     
0000001111111                            7                                                   0           
1111000111111
;

data want;
 set have;
 want=(verify(x_all,'1')&amp;gt;1)*(verify(x_all,'1')-1);
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 May 2020 18:47:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648657#M194354</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-05-18T18:47:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum a string variable until you reach a certain character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648659#M194355</link>
      <description>&lt;P&gt;Seems to me this logic simplifies to finding the first 0.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it's the first character you get a 0. If it's not the first 0, then you subtract 1 to find the position of the last 1 which is the sum of the values up to that point.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you find no 0's, that means you have all ones, which is the length of the string.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;

x_total = findc(x_all, '0');

if x_total = 0 then x_total = length(x_all);
else if x_total &amp;gt; 0 then x_total - 1;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 May 2020 18:56:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648659#M194355</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-05-18T18:56:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum a string variable until you reach a certain character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648664#M194357</link>
      <description>&lt;P&gt;Do you want to sum the digits or just count them?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the VERIFY() function to find the first location that is not a '1'.&amp;nbsp; Make sure to append something in case all of string is filled with ones.&amp;nbsp; NOTE: Your first example as 7 ones, not six.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input str :$20. wrong right ;
  want = verify(str||'0','1')-1 ;
cards;
1111111000000   6  6
0000001111111   7  0
1111000111111  10  4
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs         str         wrong    right    want

 1     1111111000000       6       6        7
 2     0000001111111       7       0        0
 3     1111000111111      10       4        4
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 May 2020 19:12:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648664#M194357</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-05-18T19:12:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum a string variable until you reach a certain character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648699#M194375</link>
      <description>Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;,&lt;BR /&gt;&lt;BR /&gt;Nice solution.&lt;BR /&gt;&lt;BR /&gt;Wondering whether this would be sufficient? &lt;BR /&gt;&lt;BR /&gt;want = verify(x_all,'1')-1 ;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 18 May 2020 22:29:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648699#M194375</guid>
      <dc:creator>biopharma</dc:creator>
      <dc:date>2020-05-18T22:29:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum a string variable until you reach a certain character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648700#M194376</link>
      <description>&lt;P&gt;Yes indeed. Good catch. I'll have to be a more diligent like you are. Thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 18 May 2020 22:43:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648700#M194376</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-05-18T22:43:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum a string variable until you reach a certain character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648704#M194378</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/254033"&gt;@biopharma&lt;/a&gt;&amp;nbsp; I just sho&lt;SPAN&gt;wed my mother(a retired banker) how elegantly you made it more terse. However she thinks it's better to have boolean 1 capture in case of missings and value not padded&amp;nbsp;with blank i.e if incoming data is equivalent to something like&amp;nbsp; &lt;EM&gt;&lt;STRONG&gt;stripped(x_all)&lt;/STRONG&gt;&lt;/EM&gt; a missing value the risk of having -1 in the result is apparent, albeit I'd still vote&amp;nbsp; opposing my mom's thoughts for the reason that occurence is less likely. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I can't generally&amp;nbsp;win against her if there's even a remote chance, so it appears the following is&amp;nbsp;what she means. lol&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input x_all :$20.;*                                 sum that code below calculates        sum that I want;
cards;
1111111000000                            6                                                   6                     
0000001111111                            7                                                   0           
1111000111111
.
;

data want;
 set have;
 want=(verify(strip(x_all),'1')-1);
 want1=(verify(strip(x_all),'1')&amp;gt;1)*(verify(strip(x_all),'1')-1);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Fun stuff:)&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 18 May 2020 23:14:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648704#M194378</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-05-18T23:14:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum a string variable until you reach a certain character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648705#M194379</link>
      <description>Thank you all for your responses, this was most helpful!</description>
      <pubDate>Mon, 18 May 2020 23:18:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648705#M194379</guid>
      <dc:creator>silversta</dc:creator>
      <dc:date>2020-05-18T23:18:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum a string variable until you reach a certain character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648706#M194380</link>
      <description>Worked like a charm, thank you!</description>
      <pubDate>Mon, 18 May 2020 23:18:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648706#M194380</guid>
      <dc:creator>silversta</dc:creator>
      <dc:date>2020-05-18T23:18:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum a string variable until you reach a certain character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648709#M194382</link>
      <description>&lt;P&gt;In general with VERIFY() you have to control for the case when the value being passed is completely filled with valid values.&amp;nbsp; In that case the result returned will be zero, not the length of the string.&amp;nbsp; So when you are using it to to find the last valid value, like in this case, you can just append some invalid character to the end of the string you pass it.&amp;nbsp; As long are your input string is not exactly 32,767 bytes long it should do what you want.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;want = verify(x_all || ' ','1')-1 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 May 2020 23:36:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648709#M194382</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-05-18T23:36:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum a string variable until you reach a certain character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648711#M194384</link>
      <description>&lt;P&gt;I agree. It's a very tricky function yet a very classy one.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 May 2020 23:37:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648711#M194384</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-05-18T23:37:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum a string variable until you reach a certain character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648811#M194434</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just for fun:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input x_all :$20.; 
cards;
1111111000000
0000001111111
1111000111111
;
run;

data want;
 set have;
 want = lengthn(prxchange('s/^(1*)(0*)(.*)/$1/', -1, x_all));
run;    &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2020 12:29:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648811#M194434</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-05-19T12:29:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum a string variable until you reach a certain character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648819#M194439</link>
      <description>&lt;P&gt;...and one more:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want1;
 set have;
 want = lengthn(scan(x_all,1,"0","M"));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2020 13:13:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648819#M194439</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-05-19T13:13:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum a string variable until you reach a certain character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648827#M194440</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp; for your time and contribution. Much appreciate it.&lt;/P&gt;
&lt;P&gt;This one too perhaps?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  want=max(0,findc(x_all,'0')-1);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 May 2020 13:28:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648827#M194440</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-05-19T13:28:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum a string variable until you reach a certain character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648832#M194441</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again for the code, it was most helpful! Is there a way to modify it to sum through a string of 1 or 2 0s in the middle. I was told that I would have to count the 0s in the middle of the string as if it were a 1, as long as there are no more than 2 of them in the middle.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;11110000011 &amp;nbsp; &amp;nbsp;= &amp;nbsp; &amp;nbsp;4&lt;/P&gt;&lt;P&gt;111001111 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; =9&lt;/P&gt;&lt;P&gt;111001111000 &amp;nbsp; =9 (would ignore the 0s at the end but count the 0s in the middle as part of the sum)&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2020 13:41:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648832#M194441</guid>
      <dc:creator>silversta</dc:creator>
      <dc:date>2020-05-19T13:41:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum a string variable until you reach a certain character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648836#M194442</link>
      <description>&lt;P&gt;Hi, try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input x_all :$20. expected ; 
cards;
11110000011 4
111001111 9
111001111000 9 
;
run;

data want;
 set have;
 want = lengthn(prxchange('s/^((1*)0{0,2}(1+))(.*)/$1/', -1, strip(x_all)));
run; 
proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2020 13:52:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648836#M194442</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-05-19T13:52:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum a string variable until you reach a certain character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648837#M194443</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/311492"&gt;@silversta&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you please explain a bit more clearly how you got this result&lt;/P&gt;
&lt;P&gt;11110000011 &amp;nbsp; &amp;nbsp;= &amp;nbsp; &amp;nbsp;4&lt;/P&gt;
&lt;P&gt;111001111 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; =9&lt;/P&gt;
&lt;P&gt;111001111000 &amp;nbsp; =9&lt;/P&gt;
&lt;P&gt;Would the above mean the following?&lt;/P&gt;
&lt;P&gt;11101111 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; =8&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;based upon &lt;EM&gt;"&lt;/EM&gt;&lt;SPAN&gt;&lt;EM&gt;Is there a way to modify it to sum through a string of 1 or 2 0s in the middle. I was told that I would have to count the 0s in the middle of the string as if it were a 1, as long as there are no more than 2 of them in the middle.&lt;/EM&gt; "&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2020 13:54:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648837#M194443</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-05-19T13:54:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum a string variable until you reach a certain character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648842#M194446</link>
      <description>Your Mom rocks! However remote the possibility, it may still be a good idea to program defensively.</description>
      <pubDate>Tue, 19 May 2020 14:04:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648842#M194446</guid>
      <dc:creator>biopharma</dc:creator>
      <dc:date>2020-05-19T14:04:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum a string variable until you reach a certain character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648843#M194447</link>
      <description>&lt;P&gt;Addendum-&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp; has answered your additional requirement even before I could begin&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2020 14:04:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-a-string-variable-until-you-reach-a-certain-character/m-p/648843#M194447</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-05-19T14:04:09Z</dc:date>
    </item>
  </channel>
</rss>

