<?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 give more than 1 loop control variable to a do loop? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-give-more-than-1-loop-control-variable-to-a-do-loop/m-p/832151#M328893</link>
    <description>&lt;P&gt;I cannot understand what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But to your question you can include a WHILE condition (or an UNTIL condition) on top of a normal start/stop interval.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do k=1 to length(sequence) while ( &amp;lt;some stopping condition);
...
end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 07 Sep 2022 15:45:07 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-09-07T15:45:07Z</dc:date>
    <item>
      <title>How to give more than 1 loop control variable to a do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-give-more-than-1-loop-control-variable-to-a-do-loop/m-p/832148#M328891</link>
      <description>&lt;P&gt;Hi SAS experts,&lt;/P&gt;
&lt;P&gt;I am trying to add 3 control conditions to a do loop to run but not able to figure it out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;what i have is a pseudo logic from where I have to build a sas code to run through my data to find first instance of a specific number in the sequence.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for this example lets use 2. attached the pseudo logic and sample data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;set sequence_event to 0
set in_sequence_position to -1
set k to 0

repeat until (( character in sequence &amp;gt;= 2 or blank) or 
		(k = length of squence)):

{
get next character in sequence 
increment in_sequence_position by 1
increment K by 1 
}&lt;/PRE&gt;
&lt;PRE&gt;if character in sequence &amp;gt; 2 
then 
increment s by 1 and 

in_sequence_position + 24
}
else if s = 'n/a'
}
return
(s,&lt;BR /&gt;in_sequence_position)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;sample Data&lt;/STRONG&gt;&lt;/P&gt;
&lt;TABLE width="575"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="86"&gt;id&lt;/TD&gt;
&lt;TD width="86"&gt;sub id&lt;/TD&gt;
&lt;TD width="403"&gt;sequence&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;1111111111111111XX111111111111121111121111111111&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;111111111111111111111111111111111111111111111111&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;554321125555555555555555555555555555555555555555&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;111111111111111111111111111111111111111111X11111&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;554321111111111111111111111111111111555555555555&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;111111111111111111111&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;11&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;111211111111111111111111111111111111111111111111&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;desired output&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="797"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="86"&gt;id&lt;/TD&gt;
&lt;TD width="86"&gt;sub id&lt;/TD&gt;
&lt;TD width="403"&gt;sequence&lt;/TD&gt;
&lt;TD width="72"&gt;S&lt;/TD&gt;
&lt;TD width="150"&gt;in_sequence_position&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;1111111111111111XX111111111111121111121111111111&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;32&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;111111111111111111111111111111111111111111111111&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;554321125555555555555555555555555555555555555555&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;111111111111111111111111111111111111111111X11111&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;554321111111111111111111111111111111555555555555&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;111111111111111111111&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;11&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;111211111111111111111111111111111111111111111111&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;any help is much appreciated.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Sep 2022 16:03:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-give-more-than-1-loop-control-variable-to-a-do-loop/m-p/832148#M328891</guid>
      <dc:creator>PrudhviB</dc:creator>
      <dc:date>2022-09-07T16:03:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to give more than 1 loop control variable to a do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-give-more-than-1-loop-control-variable-to-a-do-loop/m-p/832149#M328892</link>
      <description>&lt;P&gt;Is that input supposed to be a representation of a dataset structured like this one?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id subid sequence :$50. ;
cards;
1 1 1111111111111111XX111111111111121111121111111111
1 2 111111111111111111111111111111111111111111111111
1 3 1
2 1 554321125555555555555555555555555555555555555555
3 2 111111111111111111111111111111111111111111X11111
3 1 554321111111111111111111111111111111555555555555
4 1 111111111111111111111
4 2 11
4 3 111211111111111111111111111111111111111111111111
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What is the desired output for that input?&lt;/P&gt;</description>
      <pubDate>Wed, 07 Sep 2022 15:38:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-give-more-than-1-loop-control-variable-to-a-do-loop/m-p/832149#M328892</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-07T15:38:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to give more than 1 loop control variable to a do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-give-more-than-1-loop-control-variable-to-a-do-loop/m-p/832151#M328893</link>
      <description>&lt;P&gt;I cannot understand what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But to your question you can include a WHILE condition (or an UNTIL condition) on top of a normal start/stop interval.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do k=1 to length(sequence) while ( &amp;lt;some stopping condition);
...
end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Sep 2022 15:45:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-give-more-than-1-loop-control-variable-to-a-do-loop/m-p/832151#M328893</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-07T15:45:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to give more than 1 loop control variable to a do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-give-more-than-1-loop-control-variable-to-a-do-loop/m-p/832152#M328894</link>
      <description>&lt;P&gt;i should have included full pseudo code&amp;nbsp;&lt;/P&gt;
&lt;P&gt;this is after the do loop&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if character in seq &amp;gt; 2 
then 
increment s by 1 and 

in_sequence_position + 24
}
else if s = 'n/a'
}
return
(s,in_sequence_position)&lt;/PRE&gt;
&lt;P&gt;my desired out put should hve the "s" and "in_sequence_position" values returned.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Sep 2022 15:48:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-give-more-than-1-loop-control-variable-to-a-do-loop/m-p/832152#M328894</guid>
      <dc:creator>PrudhviB</dc:creator>
      <dc:date>2022-09-07T15:48:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to give more than 1 loop control variable to a do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-give-more-than-1-loop-control-variable-to-a-do-loop/m-p/832153#M328895</link>
      <description>&lt;P&gt;You could do that but have you seen &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.2/lefunctionsref/n1mdh2gvd5potjn14jipysvzn4o7.htm" target="_self"&gt;FINDC()&lt;/A&gt; or &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.2/lefunctionsref/p16rdsa30vmm43n1ej4936nwa01t.htm" target="_self"&gt;FINDW()&lt;/A&gt;?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you want to learn how to implement your logic specifically or would you like to learn how the SAS methods of accomplishing your objective?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the later, it may be easier to specify the logic you'd like to implement. Using built in optimized functions is definitely more efficient and faster.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/279632"&gt;@PrudhviB&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi SAS experts,&lt;/P&gt;
&lt;P&gt;I am trying to add 3 control conditions to a do loop to run but not able to figure it out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;what i have is a pseudo logic from where I have to build a sas code to run through my data to find first instance of a specific number in the sequence.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for this example lets use 2. attached the pseudo logic and sample data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;set sequence_event to 0
set in_sequence_position to -1
set k to 0

repeat until (( character in sequence &amp;gt;= 2 or blank) or 
		(k = length of squence)):

{
get next character in sequence 
increment in_sequence_position by 1
increment K by 1 
}&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;sample Data&lt;/STRONG&gt;&lt;/P&gt;
&lt;TABLE width="575"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="86"&gt;id&lt;/TD&gt;
&lt;TD width="86"&gt;sub id&lt;/TD&gt;
&lt;TD width="403"&gt;sequence&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;1111111111111111XX111111111111121111121111111111&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;111111111111111111111111111111111111111111111111&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;554321125555555555555555555555555555555555555555&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;111111111111111111111111111111111111111111X11111&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;554321111111111111111111111111111111555555555555&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;111111111111111111111&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;11&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;111211111111111111111111111111111111111111111111&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;any help is much appreciated.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Sep 2022 15:51:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-give-more-than-1-loop-control-variable-to-a-do-loop/m-p/832153#M328895</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-09-07T15:51:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to give more than 1 loop control variable to a do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-give-more-than-1-loop-control-variable-to-a-do-loop/m-p/832155#M328897</link>
      <description>&lt;P&gt;You might describe why you are doing this and what the actual expected output would be.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would guess that you may be doing something related to sequential values. Which, if that is the case might be easier, depending on actual want, than processing each character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For instance if you want to find out how many 1's are in the first sequence such as "1111111111111111XX111111111111121111121111111111"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For your consideration:&lt;/P&gt;
&lt;PRE&gt;data example;
   x="1111111111111111XX111111111111121111121111111111";
   sequences= countw(x,'1','k');
   do i= 1 to sequences;
      thisseq =scan(x,i,'1','k');
      lengthseq = countc(scan(x,i,'1','k'),'1');

      output;
   end;
run;&lt;/PRE&gt;
&lt;P&gt;In this example the Countw function uses everything except the 1 as a delimiter. So it says there are 4 sequences containing only the character 1. Then the Scan function can extract the actual sequence. The Countc function counts how many characters. Actually with all a single character the Length function would work as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, what is it you are actually trying to do?&lt;/P&gt;</description>
      <pubDate>Wed, 07 Sep 2022 15:55:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-give-more-than-1-loop-control-variable-to-a-do-loop/m-p/832155#M328897</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-09-07T15:55:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to give more than 1 loop control variable to a do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-give-more-than-1-loop-control-variable-to-a-do-loop/m-p/832156#M328898</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;my desired out put should hve the "s" and "in_sequence_position" values returned.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I don't know what you mean by those two quoted words.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Also what is the actual values you expect to get for those two variables for the actual input you provided?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Here:&amp;nbsp; Just replace the missing values in this data step and re-post to show what answers you expect.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  input id subid sequence :$50. s in_sequence_position;
cards;
1 1 1111111111111111XX111111111111121111121111111111 . .
1 2 111111111111111111111111111111111111111111111111 . .
1 3 1 . .
2 1 554321125555555555555555555555555555555555555555 . .
3 2 111111111111111111111111111111111111111111X11111 . .
3 1 554321111111111111111111111111111111555555555555 . .
4 1 111111111111111111111 . .
4 2 11 . .
4 3 111211111111111111111111111111111111111111111111 . .
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Sep 2022 16:02:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-give-more-than-1-loop-control-variable-to-a-do-loop/m-p/832156#M328898</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-07T16:02:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to give more than 1 loop control variable to a do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-give-more-than-1-loop-control-variable-to-a-do-loop/m-p/832164#M328900</link>
      <description>&lt;P&gt;So now that you have posted what you expect as output it looks like you just want to find the first occurrence of the digit 2.&lt;/P&gt;
&lt;P&gt;You also appear to want to create an extra variable is is true when the location was found (not sure what value that adds).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That is want the INDEX() or INDEXC() function will do.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id subid sequence :$50. s in_sequence_position;
cards;
1 1 1111111111111111XX111111111111121111121111111111 1 32
1 2 111111111111111111111111111111111111111111111111 0 0
1 3 1 0 0
2 1 554321125555555555555555555555555555555555555555 1 5
3 2 111111111111111111111111111111111111111111X11111 0 0
3 1 554321111111111111111111111111111111555555555555 1 5
4 1 111111111111111111111 0 0
4 2 11 0 0
4 3 111211111111111111111111111111111111111111111111 1 4
;

data want;
  set have;
  location = indexc(sequence,'2');
  found = location &amp;gt; 0 ;
run;

proc print;
  var id subid s found in: location sequence;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;                                    in_sequence_
Obs    id    subid    s    found      position      location    sequence

 1      1      1      1      1           32            32       1111111111111111XX111111111111121111121111111111
 2      1      2      0      0            0             0       111111111111111111111111111111111111111111111111
 3      1      3      0      0            0             0       1
 4      2      1      1      1            5             5       554321125555555555555555555555555555555555555555
 5      3      2      0      0            0             0       111111111111111111111111111111111111111111X11111
 6      3      1      1      1            5             5       554321111111111111111111111111111111555555555555
 7      4      1      0      0            0             0       111111111111111111111
 8      4      2      0      0            0             0       11
 9      4      3      1      1            4             4       111211111111111111111111111111111111111111111111
&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Sep 2022 16:29:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-give-more-than-1-loop-control-variable-to-a-do-loop/m-p/832164#M328900</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-07T16:29:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to give more than 1 loop control variable to a do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-give-more-than-1-loop-control-variable-to-a-do-loop/m-p/832166#M328902</link>
      <description>&lt;P&gt;If you did want to re invent the wheel using your own DO loops here is one way.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  found=0;
  do location=1 to length(sequence) while (char(sequence,location) ne '2');
  end;
  if location &amp;gt; length(sequence) then location=0;
  else found=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Sep 2022 16:35:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-give-more-than-1-loop-control-variable-to-a-do-loop/m-p/832166#M328902</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-07T16:35:55Z</dc:date>
    </item>
  </channel>
</rss>

