<?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: Is there a SAS function to flag a character value that repeats in order/pattern across columns? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-to-flag-a-character-value-that-repeats/m-p/858327#M339129</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Note that it depends on the lengths of all of the variables matching the length of the string passed to the REPEAT() function.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is a good point as it indicates how the solution could be adapted to variables T1-T10 having a common defined length &amp;gt;3 or to the similar task aiming at a series of consecutive 'No' values: The string passed to the REPEAT() function would just need to contain the trailing blanks so that the LENGTH&lt;STRONG&gt;C&lt;/STRONG&gt;() of the string would match that of the T1-T10.&lt;/P&gt;</description>
    <pubDate>Fri, 10 Feb 2023 19:09:44 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2023-02-10T19:09:44Z</dc:date>
    <item>
      <title>Is there a SAS function to flag a character value that repeats in order/pattern across columns?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-to-flag-a-character-value-that-repeats/m-p/858265#M339103</link>
      <description>&lt;P&gt;Hello SAS Community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset with close to 1 million rows. I want to find if the value 'Yes' is in sequence across the columns like below. It should be all 'Yes' without any other value in between or no missing. Can you please help? I tried array, but it only flags if a specific value like 'Yes' is found.&lt;/P&gt;&lt;P&gt;Have:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;T1&amp;nbsp; &amp;nbsp; T2&amp;nbsp; &amp;nbsp;T3&amp;nbsp; &amp;nbsp;T4&amp;nbsp; T5&amp;nbsp; T6&amp;nbsp; T7 T8 T9 T10&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Yes&amp;nbsp; No&amp;nbsp; &amp;nbsp;Yes&amp;nbsp;Yes&amp;nbsp;Yes No&amp;nbsp;Yes&amp;nbsp; .&amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;Yes&amp;nbsp;&amp;nbsp;Yes&amp;nbsp;Yes&amp;nbsp;Yes&amp;nbsp;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;.&lt;/P&gt;&lt;P&gt;Yes&amp;nbsp;Yes&amp;nbsp;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; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;No&amp;nbsp; &amp;nbsp;No&amp;nbsp; No&amp;nbsp; No&amp;nbsp; 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;&lt;STRONG&gt;T1&amp;nbsp; &amp;nbsp; T2&amp;nbsp; &amp;nbsp;T3&amp;nbsp; &amp;nbsp;T4&amp;nbsp; T5&amp;nbsp; T6&amp;nbsp; T7 T8 T9 T10&amp;nbsp; &amp;nbsp; &amp;nbsp; Flag&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Yes&amp;nbsp; No&amp;nbsp; &amp;nbsp;Yes&amp;nbsp;Yes&amp;nbsp;Yes No&amp;nbsp;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;0&lt;/P&gt;&lt;P&gt;Yes&amp;nbsp;&amp;nbsp;Yes&amp;nbsp;Yes&amp;nbsp;Yes&amp;nbsp;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; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;Yes&amp;nbsp;Yes&amp;nbsp;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; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;No&amp;nbsp; &amp;nbsp;No&amp;nbsp; No&amp;nbsp; No&amp;nbsp; No Yes No Yes Yes No&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2023 14:48:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-to-flag-a-character-value-that-repeats/m-p/858265#M339103</guid>
      <dc:creator>SP01</dc:creator>
      <dc:date>2023-02-10T14:48:24Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a SAS function to flag a character value that repeats in order/pattern across columns?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-to-flag-a-character-value-that-repeats/m-p/858285#M339115</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
array t{*} t1-t10;
flag = 1;
do i = 1 to dim(t);
  if t{i} not in ('Yes',``) then flag = 0;
end;
drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested, posted from my tablet.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2023 15:38:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-to-flag-a-character-value-that-repeats/m-p/858285#M339115</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-02-10T15:38:21Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a SAS function to flag a character value that repeats in order/pattern across columns?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-to-flag-a-character-value-that-repeats/m-p/858291#M339116</link>
      <description>&lt;P&gt;First let's make some better test data that has more of conditions you mentioned.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input (T1-T10) (:$3.);
cards;
Yes No  Yes Yes Yes No  Yes .   .   .
Yes Yes Yes Yes Yes .   .   .   .   .
Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes
Yes Yes .   Yes .   .   .   .   .   .
Yes Yes Yes .   .   .   .   .   .   .
No  No  No  No  No  Yes No  Yes Yes No
.   .   .   .   .   .   .   .   .   .
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So just scan the list until you hit one that is not Yes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have ;
  array t [10];
  flag=cmiss(of t[*]) &amp;lt; dim(t);
  do index=1 to dim(T)-cmiss(of t{*]) while(flag=1);
    flag=(t[index] = 'Yes');
  end;
  drop index;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1676045498351.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/80307iFE0C33503ED0082A/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1676045498351.png" alt="Tom_0-1676045498351.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2023 16:11:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-to-flag-a-character-value-that-repeats/m-p/858291#M339116</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-02-10T16:11:50Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a SAS function to flag a character value that repeats in order/pattern across columns?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-to-flag-a-character-value-that-repeats/m-p/858302#M339121</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/432452"&gt;@SP01&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming that variables T1-T10 have length 3 and that a missing value of T1 would violate your criterion, this definition of FLAG should work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
flag=cat(of t1 t:)=repeat('Yes',10-cmiss(of t:));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2023 16:54:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-to-flag-a-character-value-that-repeats/m-p/858302#M339121</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2023-02-10T16:54:43Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a SAS function to flag a character value that repeats in order/pattern across columns?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-to-flag-a-character-value-that-repeats/m-p/858308#M339123</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/432452"&gt;@SP01&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming that variables T1-T10 have length 3 and that a missing value of T1 would violate your criterion, this definition of FLAG should work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
flag=cat(of t1 t:)=repeat('Yes',10-cmiss(of t:));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That is simple, but remember that REPEAT() wants the count of the EXTRA copies to append so subtract 1.&lt;/P&gt;
&lt;P&gt;Note that it does not handle embedded missing.&lt;/P&gt;
&lt;PRE&gt;1131  data want;
1132    set have ;
1133    array t [10];
1134    flag=cmiss(of t[*]) &amp;lt; dim(t);
1135    do index=1 to dim(T)-cmiss(of t{*]) while(flag=1);
1136      flag=(t[index] = 'Yes');
1137    end;
1138    drop index;
1139    flag2 = (cats(of t[*])=repeat('Yes',dim(t)-cmiss(of t[*])-1));
1140  run;

NOTE: Argument 2 to function REPEAT('Yes',-1) at line 1139 column 26 is invalid.
T1=  T2=  T3=  T4=  T5=  T6=  T7=  T8=  T9=  T10=  flag=0 index=1 flag2=1 _ERROR_=1 _N_=7
NOTE: There were 7 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.WANT has 7 observations and 12 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds
&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1676048412476.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/80313iABEA34FDBB15C766/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1676048412476.png" alt="Tom_0-1676048412476.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;You could fix the all missing case by adding a MAX() function so that the count cannot be negative.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  flag2 = (cats(of t[*])=repeat('Yes',max(0,dim(t)-cmiss(of t[*])-1)));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2023 17:03:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-to-flag-a-character-value-that-repeats/m-p/858308#M339123</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-02-10T17:03:26Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a SAS function to flag a character value that repeats in order/pattern across columns?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-to-flag-a-character-value-that-repeats/m-p/858314#M339126</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for checking my solution. I still think it is correct and I've just confirmed that with a HAVE dataset comprising all 3**10 possible combinations of 'Yes', 'No' and ' '.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The peculiarity of the REPEAT function that you mention is the reason why I use &lt;FONT face="courier new,courier"&gt;cat(of &lt;STRONG&gt;t1&lt;/STRONG&gt; t:)&lt;/FONT&gt; rather than&amp;nbsp;&lt;FONT face="courier new,courier"&gt;cat(of t:)&lt;/FONT&gt;. This works in particular for the "all missing" case. There's also no problem with "embedded" missings because CAT (unlike CATS, which is what you are using for your FLAG2) does not compress them.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2023 17:25:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-to-flag-a-character-value-that-repeats/m-p/858314#M339126</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2023-02-10T17:25:37Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a SAS function to flag a character value that repeats in order/pattern across columns?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-to-flag-a-character-value-that-repeats/m-p/858322#M339128</link>
      <description>&lt;P&gt;I see, looks good.&lt;/P&gt;
&lt;P&gt;Note that it depends on the lengths of all of the variables matching the length of the string passed to the REPEAT() function.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2023 18:29:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-to-flag-a-character-value-that-repeats/m-p/858322#M339128</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-02-10T18:29:38Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a SAS function to flag a character value that repeats in order/pattern across columns?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-to-flag-a-character-value-that-repeats/m-p/858327#M339129</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Note that it depends on the lengths of all of the variables matching the length of the string passed to the REPEAT() function.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is a good point as it indicates how the solution could be adapted to variables T1-T10 having a common defined length &amp;gt;3 or to the similar task aiming at a series of consecutive 'No' values: The string passed to the REPEAT() function would just need to contain the trailing blanks so that the LENGTH&lt;STRONG&gt;C&lt;/STRONG&gt;() of the string would match that of the T1-T10.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2023 19:09:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-to-flag-a-character-value-that-repeats/m-p/858327#M339129</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2023-02-10T19:09:44Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a SAS function to flag a character value that repeats in order/pattern across columns?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-to-flag-a-character-value-that-repeats/m-p/858350#M339135</link>
      <description>&lt;P&gt;Thank you, Kurt! This works.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2023 21:30:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-to-flag-a-character-value-that-repeats/m-p/858350#M339135</guid>
      <dc:creator>SP01</dc:creator>
      <dc:date>2023-02-10T21:30:33Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a SAS function to flag a character value that repeats in order/pattern across columns?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-to-flag-a-character-value-that-repeats/m-p/858351#M339136</link>
      <description>&lt;P&gt;Thank you for your time, Tom! Your solution works as well.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2023 21:31:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-to-flag-a-character-value-that-repeats/m-p/858351#M339136</guid>
      <dc:creator>SP01</dc:creator>
      <dc:date>2023-02-10T21:31:46Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a SAS function to flag a character value that repeats in order/pattern across columns?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-to-flag-a-character-value-that-repeats/m-p/858352#M339137</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2023 21:32:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-to-flag-a-character-value-that-repeats/m-p/858352#M339137</guid>
      <dc:creator>SP01</dc:creator>
      <dc:date>2023-02-10T21:32:10Z</dc:date>
    </item>
  </channel>
</rss>

