<?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 Recognize pattern in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/916664#M361037</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have a data set with char field that contain 6 figures 1/0.&lt;/P&gt;
&lt;P&gt;I want to identify the following pattern (If this pattern then Indicator=1 else 0).&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Block A- block of '1's in the right side&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;In the right side there will be continuous of one or several '1's and last number must be 1&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Block B- block of '0's in the left side of block A&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;There can be one zero or multiple zeros in consecutive&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Block C- block of '1's in the left side of block A&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;There can be one '1' or multiple '1's in consecutive&lt;/P&gt;
&lt;P&gt;examples:&lt;/P&gt;
&lt;P&gt;010101 -This pattern meet the criteria because Block A-1&amp;nbsp; Block B-0 Block C-1&lt;/P&gt;
&lt;P&gt;000001--This pattern doesn't meet the criteria&lt;/P&gt;
&lt;P&gt;000011--This pattern doesn't meet the criteria&lt;/P&gt;
&lt;P&gt;101101-This pattern meet the criteria because Block A-1&amp;nbsp; Block B-0 Block C-11&lt;/P&gt;
&lt;P&gt;101001-This pattern meet the criteria because Block A-1&amp;nbsp; Block B-00 Block C-1&lt;/P&gt;
&lt;P&gt;010011-This pattern meet the criteria because Block A-11&amp;nbsp; Block B-00 Block C-1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the way to recognize this pattern?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
input X $;
cards;
010101 
000001
000011
000111
001111
011111
111111
110011
110111
111001
100001
001001
001011
010011
101001
101101
;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 18 Feb 2024 08:39:05 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2024-02-18T08:39:05Z</dc:date>
    <item>
      <title>Recognize pattern</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/916664#M361037</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have a data set with char field that contain 6 figures 1/0.&lt;/P&gt;
&lt;P&gt;I want to identify the following pattern (If this pattern then Indicator=1 else 0).&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Block A- block of '1's in the right side&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;In the right side there will be continuous of one or several '1's and last number must be 1&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Block B- block of '0's in the left side of block A&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;There can be one zero or multiple zeros in consecutive&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Block C- block of '1's in the left side of block A&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;There can be one '1' or multiple '1's in consecutive&lt;/P&gt;
&lt;P&gt;examples:&lt;/P&gt;
&lt;P&gt;010101 -This pattern meet the criteria because Block A-1&amp;nbsp; Block B-0 Block C-1&lt;/P&gt;
&lt;P&gt;000001--This pattern doesn't meet the criteria&lt;/P&gt;
&lt;P&gt;000011--This pattern doesn't meet the criteria&lt;/P&gt;
&lt;P&gt;101101-This pattern meet the criteria because Block A-1&amp;nbsp; Block B-0 Block C-11&lt;/P&gt;
&lt;P&gt;101001-This pattern meet the criteria because Block A-1&amp;nbsp; Block B-00 Block C-1&lt;/P&gt;
&lt;P&gt;010011-This pattern meet the criteria because Block A-11&amp;nbsp; Block B-00 Block C-1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the way to recognize this pattern?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
input X $;
cards;
010101 
000001
000011
000111
001111
011111
111111
110011
110111
111001
100001
001001
001011
010011
101001
101101
;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Feb 2024 08:39:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/916664#M361037</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-02-18T08:39:05Z</dc:date>
    </item>
    <item>
      <title>Re: Recognize pattern</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/916665#M361038</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
input X $;
cards;
010101 
000001
000011
000111
001111
011111
111111
110011
110111
111001
100001
001001
001011
010011
101001
101101
;
Run;
data want;
 set have;
 y=prxchange('s/0+/0/',-1,x);
 z=prxchange('s/1+/1/',-1,y);
 Indicator=ifn(find(z,'101'),1,0);
 drop y z;
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 18 Feb 2024 09:27:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/916665#M361038</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-02-18T09:27:27Z</dc:date>
    </item>
    <item>
      <title>Re: Recognize pattern</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/916667#M361040</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for supplying the input data in a data step. Please supply the expected output data in a data step too.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please also clarify the following if&amp;nbsp;the examples "000001" &amp;amp; "000011" don't meet the criteria because they do not satisfy Block C or is it something else?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Sun, 18 Feb 2024 09:48:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/916667#M361040</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2024-02-18T09:48:41Z</dc:date>
    </item>
    <item>
      <title>Re: Recognize pattern</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/916668#M361041</link>
      <description>&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;May you please explain&amp;nbsp;&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;y=prxchange('s/0+/0/',-1,x);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Feb 2024 09:49:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/916668#M361041</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-02-18T09:49:42Z</dc:date>
    </item>
    <item>
      <title>Re: Recognize pattern</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/916719#M361086</link>
      <description>It is changing any continuous 0s (next to each other) to a single 0.&lt;BR /&gt;E.X.&lt;BR /&gt;10001 -&amp;gt;101&lt;BR /&gt;001    -&amp;gt; 01&lt;BR /&gt;&lt;BR /&gt;So does &lt;BR /&gt;z=prxchange('s/1+/1/',-1,y);&lt;BR /&gt;change 1s to 1 .</description>
      <pubDate>Mon, 19 Feb 2024 01:00:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/916719#M361086</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-02-19T01:00:11Z</dc:date>
    </item>
    <item>
      <title>Re: Recognize pattern</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/916720#M361087</link>
      <description>"000001" &lt;BR /&gt; "000011"&lt;BR /&gt;They don't meet the criteria of block C (block C doesn't exist for them)</description>
      <pubDate>Mon, 19 Feb 2024 02:04:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/916720#M361087</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-02-19T02:04:53Z</dc:date>
    </item>
    <item>
      <title>Re: Recognize pattern</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/916721#M361088</link>
      <description>What is the meaning of "-1" in the formula?</description>
      <pubDate>Mon, 19 Feb 2024 02:03:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/916721#M361088</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-02-19T02:03:43Z</dc:date>
    </item>
    <item>
      <title>Re: Recognize pattern</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/917066#M361234</link>
      <description>That means replace 0s  to a single 0 any times as possible, &lt;BR /&gt;If it was 1 that means replace only one time.&lt;BR /&gt;i.e.&lt;BR /&gt;00010001 -&amp;gt;010001</description>
      <pubDate>Wed, 21 Feb 2024 01:40:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/917066#M361234</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-02-21T01:40:46Z</dc:date>
    </item>
    <item>
      <title>Re: Recognize pattern</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/917315#M361345</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*
Sorry. 
I found a problem in my code.
if you want 010100 be NOT matched, try this one:
*/

Data have;
input X $;
cards;
010101
010100
;
Run;
data want;
 set have;
 y=prxchange('s/0+/0/',-1,x);
 z=prxchange('s/1+/1/',-1,y);
 Indicator=ifn(prxmatch('/101$/',strip(z)),1,0);
 drop y z;
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Feb 2024 07:39:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/917315#M361345</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-02-22T07:39:54Z</dc:date>
    </item>
    <item>
      <title>Re: Recognize pattern</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/917317#M361346</link>
      <description>&lt;P&gt;You already have an answer but, just for fun, one more:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
input X $;
cards;
010101 
000001
000011
000111
001111
011111
111111
110011
110111
111001
100001
001001
001011
010011
101001
101101
101100
;
Run;

data want;
  set have;
    marker = 
        mod(X,2) /* not ends with 0 */               
        * 
        (countw(X,"0","B") &amp;gt; 1) /* has at least 2 sequences of 1s (counting from right) */
    ;
run;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;{EDIT:}&lt;/P&gt;
&lt;P&gt;Of course if zeros on right aren't a problem (e.g., 010110 should be marked) then it reduces just to:&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;marker = (countw(X,"0","B") &amp;gt; 1); &lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;{EDIT 2:}&lt;/P&gt;
&lt;P&gt;To avoid ugly "types conversion" note in the log, the MOD() can be replaced with CHAR() function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    marker = 
        char(X,6) = "1" /* not ends with 0 */               
        * 
        (countw(X,"0","B") &amp;gt; 1) /* has at least 2 sequences of 1s (counting from right) */
    ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2024 08:26:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/917317#M361346</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-02-22T08:26:02Z</dc:date>
    </item>
    <item>
      <title>Re: Recognize pattern</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/917319#M361348</link>
      <description>The rule is that if there is 1( or multiple 1's) and then 0( or multiple 0) and then 1( or multiple 1's) then indicator=1 .&lt;BR /&gt;It means that there is "hole" of zero between one's.  In real life it mean that customer was exist snd then disappeared and then exist again</description>
      <pubDate>Thu, 22 Feb 2024 09:06:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/917319#M361348</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-02-22T09:06:50Z</dc:date>
    </item>
    <item>
      <title>Re: Recognize pattern</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/917327#M361351</link>
      <description>&lt;P&gt;ok, so it looks like my code does what you need.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2024 10:27:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/917327#M361351</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-02-22T10:27:37Z</dc:date>
    </item>
    <item>
      <title>Re: Recognize pattern</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/917334#M361357</link>
      <description>&lt;P&gt;Both codes provide same result which is perfect:)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
input X $ 20.;;
cards;
010101 
000001
000011
000111
001111
011111
111111
110011
110111
111001
100001
001001
001011
010011
101001
101101
000000000001
000000000101
000000000011
000001011111
100000000001
101010101011
;
Run;

data want1;
set have;
y=prxchange('s/0+/0/',-1,x);
z=prxchange('s/1+/1/',-1,y);
Indicator1=ifn(find(z,'101'),1,0);
drop y z;
run;

data want2;
set have;
Indicator2 =  mod(X,2) /* not ends with 0 */ * (countw(X,"0","B") &amp;gt; 1) /* has at least 2 sequences of 1s (counting from right) */;
run;

proc sql;
create table compare_results(Where=(Indicator1 ne Indicator2)) as
select a.*,b.Indicator2
from want1  as a
left join want2 as b
on a.X=b.X
;
quit;
 &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Feb 2024 11:29:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/917334#M361357</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-02-22T11:29:03Z</dc:date>
    </item>
    <item>
      <title>Re: Recognize pattern</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/917335#M361358</link>
      <description>&lt;P&gt;You didn't read what I wrote in my answer about "if zeros at the end are not important"...&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2024 11:16:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/917335#M361358</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-02-22T11:16:53Z</dc:date>
    </item>
    <item>
      <title>Re: Recognize pattern</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/917336#M361359</link>
      <description>&lt;P&gt;BTW. your data step with example cuts your data in half...&lt;/P&gt;
&lt;P&gt;Should be:&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;input X $ 20.;&lt;/LI-CODE&gt;
&lt;P&gt;or something like that....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2024 11:18:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/917336#M361359</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-02-22T11:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: Recognize pattern</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/917337#M361360</link>
      <description>&lt;P&gt;Actually cannot have zero at end because the check is for customers that exist today (value 1)&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2024 11:30:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/917337#M361360</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-02-22T11:30:05Z</dc:date>
    </item>
    <item>
      <title>Re: Recognize pattern</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/917338#M361361</link>
      <description>&lt;P&gt;Zero at the RightEnd of the string or at the LeftEnd?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1010101&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1010100&amp;nbsp;&lt;/P&gt;
&lt;P&gt;0101010&amp;nbsp;&lt;/P&gt;
&lt;P&gt;0101011&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2024 11:33:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/917338#M361361</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-02-22T11:33:34Z</dc:date>
    </item>
    <item>
      <title>Re: Recognize pattern</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/917339#M361362</link>
      <description>&lt;P&gt;But remember if the length of X exceeds capabilities of:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt; mod(X,2)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;results won't be the same,&lt;/P&gt;
&lt;P&gt;to be clear you can replace MOD() with&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt; char(length(X)) = "1"&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;to verify if the last character is 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2024 11:39:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/917339#M361362</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-02-22T11:39:04Z</dc:date>
    </item>
    <item>
      <title>Re: Recognize pattern</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/917367#M361377</link>
      <description>Zero cannot be at right end because right end reflect existing of customers this month and the query check only customers existing this month</description>
      <pubDate>Thu, 22 Feb 2024 14:21:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recognize-pattern/m-p/917367#M361377</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-02-22T14:21:50Z</dc:date>
    </item>
  </channel>
</rss>

