<?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 Flag a character value that either starts or repeats in order/pattern across columns? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Flag-a-character-value-that-either-starts-or-repeats-in-order/m-p/858353#M339138</link>
    <description>&lt;P&gt;Hello SAS Community,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to find and flag rows if either the first column value 'Yes' or if the value 'Yes' is in sequence across the columns like below. It should either be that first column starts with 'Yes' or be all 'Yes' without any other value in between or no missing. Thank you for your time.&lt;/P&gt;
&lt;P&gt;Have:&lt;/P&gt;
&lt;P&gt;T1 T2 T3 T4 T5 T6 T7 T8 T9 T10&lt;/P&gt;
&lt;P&gt;Yes No Yes Yes Yes No Yes . . .&lt;/P&gt;
&lt;P&gt;Yes Yes Yes Yes Yes . . . . .&lt;/P&gt;
&lt;P&gt;Yes Yes Yes . . . . . . .&lt;/P&gt;
&lt;P&gt;No No No No No Yes No Yes Yes No&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Want:&lt;/P&gt;
&lt;P&gt;T1&amp;nbsp; T2&amp;nbsp; T3&amp;nbsp; T4&amp;nbsp; T5&amp;nbsp; T6&amp;nbsp; T7&amp;nbsp; T8&amp;nbsp; T9&amp;nbsp; T10&amp;nbsp; &amp;nbsp;Flag&lt;/P&gt;
&lt;P&gt;Yes No Yes Yes Yes No Yes&amp;nbsp; .&amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;Yes Yes Yes Yes Yes . . .&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; 1&lt;/P&gt;
&lt;P&gt;Yes Yes Yes . . . . . . .&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; 1&lt;/P&gt;
&lt;P&gt;No No No No No Yes No Yes Yes&amp;nbsp; No&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;</description>
    <pubDate>Fri, 10 Feb 2023 22:02:59 GMT</pubDate>
    <dc:creator>SP01</dc:creator>
    <dc:date>2023-02-10T22:02:59Z</dc:date>
    <item>
      <title>Flag a character value that either starts or repeats in order/pattern across columns?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-a-character-value-that-either-starts-or-repeats-in-order/m-p/858353#M339138</link>
      <description>&lt;P&gt;Hello SAS Community,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to find and flag rows if either the first column value 'Yes' or if the value 'Yes' is in sequence across the columns like below. It should either be that first column starts with 'Yes' or be all 'Yes' without any other value in between or no missing. Thank you for your time.&lt;/P&gt;
&lt;P&gt;Have:&lt;/P&gt;
&lt;P&gt;T1 T2 T3 T4 T5 T6 T7 T8 T9 T10&lt;/P&gt;
&lt;P&gt;Yes No Yes Yes Yes No Yes . . .&lt;/P&gt;
&lt;P&gt;Yes Yes Yes Yes Yes . . . . .&lt;/P&gt;
&lt;P&gt;Yes Yes Yes . . . . . . .&lt;/P&gt;
&lt;P&gt;No No No No No Yes No Yes Yes No&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Want:&lt;/P&gt;
&lt;P&gt;T1&amp;nbsp; T2&amp;nbsp; T3&amp;nbsp; T4&amp;nbsp; T5&amp;nbsp; T6&amp;nbsp; T7&amp;nbsp; T8&amp;nbsp; T9&amp;nbsp; T10&amp;nbsp; &amp;nbsp;Flag&lt;/P&gt;
&lt;P&gt;Yes No Yes Yes Yes No Yes&amp;nbsp; .&amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;Yes Yes Yes Yes Yes . . .&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; 1&lt;/P&gt;
&lt;P&gt;Yes Yes Yes . . . . . . .&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; 1&lt;/P&gt;
&lt;P&gt;No No No No No Yes No Yes Yes&amp;nbsp; No&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2023 22:02:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-a-character-value-that-either-starts-or-repeats-in-order/m-p/858353#M339138</guid>
      <dc:creator>SP01</dc:creator>
      <dc:date>2023-02-10T22:02:59Z</dc:date>
    </item>
    <item>
      <title>Re: Flag a character value that either starts or repeats in order/pattern across columns?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-a-character-value-that-either-starts-or-repeats-in-order/m-p/858370#M339141</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_1-1676078982625.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/80324i167A0A4D18922E46/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_1-1676078982625.png" alt="Patrick_1-1676078982625.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Not sure that I fully understand the "or no missing" requirement but based on the sample data provided below should work.&lt;/P&gt;
&lt;P&gt;If there are other patterns in your data to consider then please provide sample data that includes these patterns.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines dlm='|' dsd truncover;
  input (t1-t10) (:$3.) flag_want;
  datalines;
Yes|No|Yes|Yes|Yes|No|Yes||||1
Yes|Yes|Yes|Yes|Yes||||||1
Yes|Yes|Yes||||||||1
No|No|No|No|No|Yes|No|Yes|Yes|No|0
;

data want;
  set have;
  if t1='Yes' then flag_derived=1;
  else flag_derived= ( whichc('No',of t2-t10)=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_2-1676079053854.png" style="width: 545px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/80325iCCDA696D47C93450/image-dimensions/545x123?v=v2" width="545" height="123" role="button" title="Patrick_2-1676079053854.png" alt="Patrick_2-1676079053854.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;...and given that in the "data" you posted missings are represented as dots here the code that works with numerical variables.&amp;nbsp;&lt;BR /&gt;Going forward: Please post sample data always via a working SAS datastep as this helps us help you.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  value YesNo
   0='No'
   1='Yes'
   ;
run;

data have;
  infile datalines dlm='|' dsd truncover;
  input (t1-t10) (:best32.) flag_want;
  format t1-t10 YesNo.;
  datalines;
1|0|1|1|1|0|1||||1
1|1|1|1|1||||||1
1|1|1||||||||1
0|0|0|0|0|1|0|1|1|0|0
;

data want;
  set have;
  if t1=1 then flag_derived=1;
  else flag_derived= ( whichn(0,of t2-t10)=0 );
run;

proc print data=want;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Feb 2023 01:41:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-a-character-value-that-either-starts-or-repeats-in-order/m-p/858370#M339141</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-02-11T01:41:13Z</dc:date>
    </item>
    <item>
      <title>Re: Flag a character value that either starts or repeats in order/pattern across columns?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-a-character-value-that-either-starts-or-repeats-in-order/m-p/858430#M339164</link>
      <description>&lt;P&gt;If you are going to have a lot to questions about stuff like this, especially if you get to "at least X yes values", "at most" "more yes than no" or similar you may want to save yourself a lot of headaches and either convert the Yes/No to 1/0 (my choice) or reduce them to single character Y/N.&lt;/P&gt;
&lt;P&gt;If values are numeric 1/0 coded then you have the functions SUM, that would give a total number of 1's, N the number of variables with any value, Nmiss the number of missing, Range largest - smallest (1 as range tells you that there are some of both values and 0 that all populated values are 1), mean decimal percentage of 1's,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or using the single letter you could combine them into one string and use Countc to get counts of Y and N.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also if any of your actual values include MISSING between values you should include some in the examples.&lt;/P&gt;</description>
      <pubDate>Sun, 12 Feb 2023 07:41:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-a-character-value-that-either-starts-or-repeats-in-order/m-p/858430#M339164</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-02-12T07:41:56Z</dc:date>
    </item>
  </channel>
</rss>

