<?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: Index options for those digits that doesn't follow the defined pattern in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Index-options-for-those-digits-that-doesn-t-follow-the-defined/m-p/625547#M35541</link>
    <description>&lt;P&gt;Here one way of doing this. Code based on example from docu &lt;A href="https://go.documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=n1obc9u7z3225mn1npwnassehff0.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  id=1;
  customer_historic='00000666668888888888880000000000000000777777777777777777770000000006666666';
  output;
  id=2;
  call missing(customer_historic);
  output;
  stop;
run;

data want(drop=_:);
  set have;
  length value $1;
  _exprid = prxparse('/(\d)\1*/');
  _start = 1;
  _stop = lengthn(customer_historic);

  if _stop=0 then output;
  else
    do;
    /* Use PRXNEXT to find the first instance of the pattern, */
    /* then use DO WHILE to find all further instances.       */
    /* PRXNEXT changes the _start parameter so that searching  */
    /* begins again after the last match.                     */
    call prxnext(_exprid, _start, _stop, customer_historic, first_numb_sequence , _len);

    do while (first_numb_sequence  &amp;gt; 0);
      value = substrn(customer_historic, first_numb_sequence , 1);
      last_numb_sequence=first_numb_sequence+_len-1;
      output;
      call prxnext(_exprid, _start, _stop, customer_historic, first_numb_sequence , _len);
    end;
  end;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/36206iE5AC1401CFBE1CCE/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 18 Feb 2020 09:22:43 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2020-02-18T09:22:43Z</dc:date>
    <item>
      <title>Index options for those digits that doesn't follow the defined pattern</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Index-options-for-those-digits-that-doesn-t-follow-the-defined/m-p/625501#M35538</link>
      <description>&lt;P&gt;Hi everyone, I'm working with informations about customers along 136 months.&lt;/P&gt;&lt;P&gt;What I'm working on is an specific information about those customers that express a situation that can from a month to another. With this data in hands I'm building a report to specify the duration (in months) of each situation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, concatenating all these situation for an hypothetic customer we would have:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;customer_historic='00000666668888888888880000000000000000777777777777777777770000000006666666'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At first I could say that on the first five months the situation was 0 and lasted for 5 months.&lt;/P&gt;&lt;P&gt;And since the 6th month the situation began to be 6, and it lasted for 5 months as well.&lt;/P&gt;&lt;P&gt;And then, from the 11th month it started to be 8, and it lasted for 8 months&lt;/P&gt;&lt;P&gt;.....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But, using formulas, I just can identify the beginning of this sequence, which could be done using:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FIRST_NUMB_SEQUENCE = INDEX(customer_historic,'0');&lt;/P&gt;&lt;P&gt;Which the result would be&amp;nbsp;FIRST_NUMB_SEQUENCE = '1'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know a way to identify when, along the sequence, the digit starts to be different from 6 ? Is possible to do that using INDEX function ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or an alternative way.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2020 02:44:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Index-options-for-those-digits-that-doesn-t-follow-the-defined/m-p/625501#M35538</guid>
      <dc:creator>claudiopcjr</dc:creator>
      <dc:date>2020-02-18T02:44:15Z</dc:date>
    </item>
    <item>
      <title>Re: Index options for those digits that doesn't follow the defined pattern</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Index-options-for-those-digits-that-doesn-t-follow-the-defined/m-p/625505#M35539</link>
      <description>&lt;P&gt;Many suggestions might be made, but why not show us what the resulting data set would look like?&amp;nbsp; That will help narrow down the relevant answers.&amp;nbsp; For instance, if a customer's history has, say 7 "regimes", do you want seven output records (and what would they look like)? &amp;nbsp; If some other structure, what would it look like?&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2020 03:07:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Index-options-for-those-digits-that-doesn-t-follow-the-defined/m-p/625505#M35539</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-02-18T03:07:33Z</dc:date>
    </item>
    <item>
      <title>Re: Index options for those digits that doesn't follow the defined pattern</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Index-options-for-those-digits-that-doesn-t-follow-the-defined/m-p/625547#M35541</link>
      <description>&lt;P&gt;Here one way of doing this. Code based on example from docu &lt;A href="https://go.documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=n1obc9u7z3225mn1npwnassehff0.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  id=1;
  customer_historic='00000666668888888888880000000000000000777777777777777777770000000006666666';
  output;
  id=2;
  call missing(customer_historic);
  output;
  stop;
run;

data want(drop=_:);
  set have;
  length value $1;
  _exprid = prxparse('/(\d)\1*/');
  _start = 1;
  _stop = lengthn(customer_historic);

  if _stop=0 then output;
  else
    do;
    /* Use PRXNEXT to find the first instance of the pattern, */
    /* then use DO WHILE to find all further instances.       */
    /* PRXNEXT changes the _start parameter so that searching  */
    /* begins again after the last match.                     */
    call prxnext(_exprid, _start, _stop, customer_historic, first_numb_sequence , _len);

    do while (first_numb_sequence  &amp;gt; 0);
      value = substrn(customer_historic, first_numb_sequence , 1);
      last_numb_sequence=first_numb_sequence+_len-1;
      output;
      call prxnext(_exprid, _start, _stop, customer_historic, first_numb_sequence , _len);
    end;
  end;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/36206iE5AC1401CFBE1CCE/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2020 09:22:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Index-options-for-those-digits-that-doesn-t-follow-the-defined/m-p/625547#M35541</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-02-18T09:22:43Z</dc:date>
    </item>
    <item>
      <title>Re: Index options for those digits that doesn't follow the defined pattern</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Index-options-for-those-digits-that-doesn-t-follow-the-defined/m-p/629238#M35630</link>
      <description />
      <pubDate>Tue, 03 Mar 2020 19:47:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Index-options-for-those-digits-that-doesn-t-follow-the-defined/m-p/629238#M35630</guid>
      <dc:creator>claudiopcjr</dc:creator>
      <dc:date>2020-03-03T19:47:23Z</dc:date>
    </item>
  </channel>
</rss>

