<?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: search for transition pattern in multiple columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/search-for-transition-pattern-in-multiple-columns/m-p/912337#M359661</link>
    <description>&lt;P&gt;It would really help if you could share sample data not via screen shot but in useable form - ideally via working SAS data step code that creates it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For row 7 in below sample data: The current logic will return a match. Is that what you want to happen? If not then can you please further specify the selection logic.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover dsd;
  input (st1-st7) ($);
datalines;
6,0,,D,0,2
0,1,0,5
0,,0,D,0,2
0,D,0,0,2
,,0,6,0,2
,0,6,6,0,2
0,6,9,D,0,6,2
;

data want;
  set have;
  flag = prxmatch('/0.*?[D46].*?0.*?2/oi',strip(cats(of st1-st7))) &amp;gt; 0;
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-1705713880417.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/92832i627A39FC065CABD0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1705713880417.png" alt="Patrick_0-1705713880417.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 20 Jan 2024 01:26:05 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2024-01-20T01:26:05Z</dc:date>
    <item>
      <title>search for transition pattern in multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/search-for-transition-pattern-in-multiple-columns/m-p/912279#M359651</link>
      <description>&lt;P&gt;Hello, this is similar to another thread i posted before here:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/How-to-check-for-an-array-of-columns-and-search-for-specific/m-p/887340#M350582" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/How-to-check-for-an-array-of-columns-and-search-for-specific/m-p/887340#M350582&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;and i am sorry but i can't figure out how to flag the rows when a specific pattern occurs. Basically I want to flag any row that have a sequence of the following pattern: 0 --&amp;gt; D or 4 or 6 or 9 --&amp;gt; 0 ---&amp;gt; 2. Data structure is the same as in the pasted link above.&amp;nbsp;There could be other values in between those sequence (which is okay) so it's not necessarily they are right next to each other.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below is the code I've trying to make it work but it is not. Somehow it's not capturing the second time 0 appears in the rows. Any suggestions? Thanks!!&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA TEST3;
  SET TEST2;
  ARRAY COLNAME st1-st42; 
  FLG = 0;
  FLG1 = 0;
  FLG2 = 0;

  i=whichc('0', of colname[*]);

  if i then do i = i + 1 to dim(colname) until (flg);
    flg = colname[i] IN ('D', '4', '6', '9');
  end;

  if flg then do i = i + 1 to dim(colname) until (flg1);
    flg1 = colname[i] = '0';
  end;

  if flg1 then do i = i + 1 to dim(colname) until (flg2);
    flg2 = colname[i] = '2';
  end;

  if flg and flg1 and flg2; 
  DROP FLG FLG1 FLG2 i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Jan 2024 21:00:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/search-for-transition-pattern-in-multiple-columns/m-p/912279#M359651</guid>
      <dc:creator>kevsma</dc:creator>
      <dc:date>2024-01-19T21:00:53Z</dc:date>
    </item>
    <item>
      <title>Re: search for transition pattern in multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/search-for-transition-pattern-in-multiple-columns/m-p/912308#M359656</link>
      <description>&lt;P&gt;I really cannot follow what this means: have a sequence of the following pattern: 0 --&amp;gt; D or 4 or 6 or 9 --&amp;gt; 0 ---&amp;gt; 2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also your previous post in that thread did not actually provide workable data. Some of use made up something but not to work with this question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Suggestion: Following the example set by others in that other thread create data and then walk us through examples of the various cases to show the the desired output. Include as many different cases as you can provide. Include some that are not one of your sequences. Show the results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jan 2024 22:22:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/search-for-transition-pattern-in-multiple-columns/m-p/912308#M359656</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-01-19T22:22:40Z</dc:date>
    </item>
    <item>
      <title>Re: search for transition pattern in multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/search-for-transition-pattern-in-multiple-columns/m-p/912314#M359657</link>
      <description>&lt;P&gt;Sorry this is confusing to you.&lt;/P&gt;
&lt;P&gt;Below i pasted a screenshot of my data table, each row represents a unique ID and I have 43 columns with values indicating the status for each time point. All I need is to flag out the rows when the specific pattern occurs: 0 to (4 or D or 6 or 9) then back to 0 and eventually to 2.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I highlighted a few examples below that would fit the criterion here but the rest don't either because no 4/6/9/D in between the 0s or no 0 before 2, etc. I hope this helps clarify a bit.&amp;nbsp;&lt;/P&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="kevsma_3-1705703571533.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/92817iE187D6C70EAD13D7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="kevsma_3-1705703571533.png" alt="kevsma_3-1705703571533.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jan 2024 22:34:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/search-for-transition-pattern-in-multiple-columns/m-p/912314#M359657</guid>
      <dc:creator>kevsma</dc:creator>
      <dc:date>2024-01-19T22:34:12Z</dc:date>
    </item>
    <item>
      <title>Re: search for transition pattern in multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/search-for-transition-pattern-in-multiple-columns/m-p/912337#M359661</link>
      <description>&lt;P&gt;It would really help if you could share sample data not via screen shot but in useable form - ideally via working SAS data step code that creates it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For row 7 in below sample data: The current logic will return a match. Is that what you want to happen? If not then can you please further specify the selection logic.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover dsd;
  input (st1-st7) ($);
datalines;
6,0,,D,0,2
0,1,0,5
0,,0,D,0,2
0,D,0,0,2
,,0,6,0,2
,0,6,6,0,2
0,6,9,D,0,6,2
;

data want;
  set have;
  flag = prxmatch('/0.*?[D46].*?0.*?2/oi',strip(cats(of st1-st7))) &amp;gt; 0;
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-1705713880417.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/92832i627A39FC065CABD0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1705713880417.png" alt="Patrick_0-1705713880417.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jan 2024 01:26:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/search-for-transition-pattern-in-multiple-columns/m-p/912337#M359661</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-01-20T01:26:05Z</dc:date>
    </item>
    <item>
      <title>Re: search for transition pattern in multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/search-for-transition-pattern-in-multiple-columns/m-p/912367#M359673</link>
      <description>&lt;P&gt;&amp;nbsp;Why bother to make a PICTURE of data?&amp;nbsp; Can't you just copy the actual TEXT?&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jan 2024 21:52:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/search-for-transition-pattern-in-multiple-columns/m-p/912367#M359673</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-01-20T21:52:21Z</dc:date>
    </item>
    <item>
      <title>Re: search for transition pattern in multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/search-for-transition-pattern-in-multiple-columns/m-p/912420#M359691</link>
      <description>&lt;P&gt;I tested your code. It seems to capture the transitions just fine in the test data that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;wrote. Is it because your data contains something that is not shown in the picture? (For instance, if the second 0 contains leading blanks).&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jan 2024 08:01:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/search-for-transition-pattern-in-multiple-columns/m-p/912420#M359691</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2024-01-22T08:01:49Z</dc:date>
    </item>
    <item>
      <title>Re: search for transition pattern in multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/search-for-transition-pattern-in-multiple-columns/m-p/912753#M359786</link>
      <description>&lt;P&gt;you are right! I just tested mine and it returns the same results as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;wrote. it looks like I forgot to dedup before running the codes, that's why i was seeing those odd entries. mystery solved!&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jan 2024 19:29:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/search-for-transition-pattern-in-multiple-columns/m-p/912753#M359786</guid>
      <dc:creator>kevsma</dc:creator>
      <dc:date>2024-01-23T19:29:15Z</dc:date>
    </item>
    <item>
      <title>Re: search for transition pattern in multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/search-for-transition-pattern-in-multiple-columns/m-p/912754#M359787</link>
      <description>&lt;P&gt;thanks so much&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;! your code works like a charm and is much more concise than mine, I absolutely like your solution. and yes, i'll paste in text data lines next time, sorry for the inconvenience it has caused. thanks again for the help!&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jan 2024 19:30:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/search-for-transition-pattern-in-multiple-columns/m-p/912754#M359787</guid>
      <dc:creator>kevsma</dc:creator>
      <dc:date>2024-01-23T19:30:30Z</dc:date>
    </item>
  </channel>
</rss>

