<?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 way to flag if there is a missing column or columns in between non-missing columns in S in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Is-there-way-to-flag-if-there-is-a-missing-column-or-columns-in/m-p/865596#M341836</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; If the gap is at the start and there is no gap after the start, we ignore this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the gap is more than one variable, we still need to flag it.&lt;/P&gt;</description>
    <pubDate>Tue, 21 Mar 2023 20:35:48 GMT</pubDate>
    <dc:creator>SP01</dc:creator>
    <dc:date>2023-03-21T20:35:48Z</dc:date>
    <item>
      <title>Is there way to flag if there is a missing column or columns in between non-missing columns in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-way-to-flag-if-there-is-a-missing-column-or-columns-in/m-p/865471#M341787</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="postcell post-layout--right"&gt;
&lt;DIV class="s-prose js-post-body"&gt;
&lt;P&gt;I tried different ways and searched on google to come up with a way to deal with this. But was unable to accomplish this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Currently, my data&amp;nbsp;looks like the below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
input col1 $ col2 $ col3 $ col4 $ col5 $ col6 $ col7 $ col8 $ col9 $ col10 $;
cards;
A B B C . D A . A . 
B A . C A D A B . . 
A B B D D D . . . . 
A . B C B D A . . . 
A B B C . D A . . . 
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;Goal:&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;I want to flag all rows that have a missing column in between. For example, if there is a column 2 missing, where col1 - col8 is the series here. Important to remember that there might be instances where the sequence finishes at col5 or col4 or col6. The rest of the columns would be missing values. We need to ignore these and only flag if there is a missing column or columns in between non-missing columns.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
    input col1 $ col2 $ col3 $ col4 $ col5 $ col6 $ col7 $ col8 $ col9 $ col10 $ flag$;
    cards;
                         flag
    A B B C . D A . A .   1
    B A . C A D A B . .   1
    A B B D D D . . . .   0
    A . B C B D A . . .   1
    A B B C . D A . . .   1
    ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Thank you for your time.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 21 Mar 2023 15:56:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-way-to-flag-if-there-is-a-missing-column-or-columns-in/m-p/865471#M341787</guid>
      <dc:creator>SP01</dc:creator>
      <dc:date>2023-03-21T15:56:35Z</dc:date>
    </item>
    <item>
      <title>Re: Is there way to flag if there is a missing column or columns in between non-missing columns in S</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-way-to-flag-if-there-is-a-missing-column-or-columns-in/m-p/865525#M341823</link>
      <description>&lt;P&gt;I would be interested in seeing just what you tried.&lt;/P&gt;
&lt;P&gt;Typically dealing with sequential processing of values on a single observation points towards an array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   array c(*) col1-col10;
   flag=0;
   do i= 1 to 8;
      if not missing(c[i]) and missing (c[i+1]) and not missing(c[i+2]) then do;
         flag=1;
         leave;
      end;
   end;
   drop i;
run;&lt;/PRE&gt;
&lt;P&gt;The index values only go from 1 to 8 because we are examining 3 variables at a time.&lt;/P&gt;
&lt;P&gt;The Leave instruction tells SAS to quit processing the loop when a case of missing is found between two non-missing values after setting the flag value.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2023 17:55:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-way-to-flag-if-there-is-a-missing-column-or-columns-in/m-p/865525#M341823</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-03-21T17:55:17Z</dc:date>
    </item>
    <item>
      <title>Re: Is there way to flag if there is a missing column or columns in between non-missing columns in S</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-way-to-flag-if-there-is-a-missing-column-or-columns-in/m-p/865585#M341832</link>
      <description>&lt;P&gt;You are missing some edge cases.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What if the gap is at the start?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What if the gap is more than one variable?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data expect;
  input (col1-col10) ($) flag ;
cards;
A B B C . D A . A . 1
B A . C A D A B . . 1
A B B D D D . . . . 0
A . B C B D A . . . 1
A B B C . D A . . . 1
. . C D E F . . . . ?
A B . . E F . . . . ?
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Mar 2023 20:07:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-way-to-flag-if-there-is-a-missing-column-or-columns-in/m-p/865585#M341832</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-21T20:07:31Z</dc:date>
    </item>
    <item>
      <title>Re: Is there way to flag if there is a missing column or columns in between non-missing columns in S</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-way-to-flag-if-there-is-a-missing-column-or-columns-in/m-p/865596#M341836</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; If the gap is at the start and there is no gap after the start, we ignore this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the gap is more than one variable, we still need to flag it.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2023 20:35:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-way-to-flag-if-there-is-a-missing-column-or-columns-in/m-p/865596#M341836</guid>
      <dc:creator>SP01</dc:creator>
      <dc:date>2023-03-21T20:35:48Z</dc:date>
    </item>
    <item>
      <title>Re: Is there way to flag if there is a missing column or columns in between non-missing columns in S</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-way-to-flag-if-there-is-a-missing-column-or-columns-in/m-p/865597#M341837</link>
      <description>&lt;P&gt;Thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I will try this code and see if it also flags the edge cases like &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; described in the comments.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2023 20:36:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-way-to-flag-if-there-is-a-missing-column-or-columns-in/m-p/865597#M341837</guid>
      <dc:creator>SP01</dc:creator>
      <dc:date>2023-03-21T20:36:42Z</dc:date>
    </item>
    <item>
      <title>Re: Is there way to flag if there is a missing column or columns in between non-missing columns in S</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-way-to-flag-if-there-is-a-missing-column-or-columns-in/m-p/865598#M341838</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;

array _c(*) c1 - c10;

do i = 1 to dim(_c);
if missing(__c[i]) and not missing(lag(_c[i])) then _flag = 1;
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;I tried the above array with lag function, but was not able to view the desired outcome.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2023 20:39:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-way-to-flag-if-there-is-a-missing-column-or-columns-in/m-p/865598#M341838</guid>
      <dc:creator>SP01</dc:creator>
      <dc:date>2023-03-21T20:39:43Z</dc:date>
    </item>
    <item>
      <title>Re: Is there way to flag if there is a missing column or columns in between non-missing columns in S</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-way-to-flag-if-there-is-a-missing-column-or-columns-in/m-p/865605#M341840</link>
      <description>&lt;P&gt;It won't because your stated requirement was " that have a missing column in between.".&lt;/P&gt;
&lt;P&gt;"A missing column" means one. If you wanted more than one to be counted the phrase could be "one or more missing values between".&lt;/P&gt;
&lt;P&gt;And won't catch the edge of start with missing because "in between". Problem should state "in between or first is missing with second present". This one is easy to check as a special case for the I=1 in the do loop I suggested.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the data had included such examples as possible ...&lt;/P&gt;
&lt;PRE&gt;data expect;
  input (col1-col10) ($) flag ;
cards;
A B B C . D A . A . 1
B A . C A D A B . . 1
A B B D D D . . . . 0
A . B C B D A . . . 1
A B B C . D A . . . 1
. . C D E F . . . . 1
A B . . E F . . . . 1
;

data want;
   set expect;
   array c (*) col1-col10;
   array n (10);
   do i=1 to dim(c);
     n[i]= i*( not missing(c[i]));
   end;
   flag = 0&amp;lt; whichn(0, of n(*)) &amp;lt; whichn(max(of n(*)),of n(*));
   drop i n1-n10;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The above creates indicator variables with values of 1 to 10 for present and 0 for missing in position 1 through 10 of the array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The WHICHN function finds the position of the value in the first parameter in a list of following values. When multiple matches may occur the first position in the ordered list is reported.&lt;/P&gt;
&lt;P&gt;So we test to see if any of the 0, if present occur and get the position. Then find the maximum value of the array and find its position. If that last number is greater than the first of the 0 then you have a missing in the "middle" or beginning.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2023 21:39:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-way-to-flag-if-there-is-a-missing-column-or-columns-in/m-p/865605#M341840</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-03-21T21:39:16Z</dc:date>
    </item>
    <item>
      <title>Re: Is there way to flag if there is a missing column or columns in between non-missing columns in S</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-way-to-flag-if-there-is-a-missing-column-or-columns-in/m-p/865609#M341841</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/432452"&gt;@SP01&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; If the gap is at the start and there is no gap after the start, we ignore this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the gap is more than one variable, we still need to flag it.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not clear if that means the the next to last row of &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;'s example is a one or not.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2023 21:41:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-way-to-flag-if-there-is-a-missing-column-or-columns-in/m-p/865609#M341841</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-03-21T21:41:16Z</dc:date>
    </item>
    <item>
      <title>Re: Is there way to flag if there is a missing column or columns in between non-missing columns in S</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-way-to-flag-if-there-is-a-missing-column-or-columns-in/m-p/865618#M341843</link>
      <description>&lt;P&gt;So use the logic you got on Stackoverflow, but skip the leading missing values.&lt;/P&gt;
&lt;P&gt;Here is one way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data expect;
  input (col1-col10) ($) flag ;
cards;
A B B C . D A . A . 1
B A . C A D A B . . 1
A B B D D D . . . . 0
A . B C B D A . . . 1
A B B C . D A . . . 1
. . C D E F . . . . 0
A B . . E F . . . . 1
;

data want ;
  set expect(drop=flag);
  array col col1-col10;
  index=whichc(coalescec(of col[*]),of col[*]);
  do index=index+1 to dim(col)-1 until (flag);
    flag=missing(col[index]) and not missing(col[index+1]);
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1679438077407.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/81887iB68C3F265D2974A8/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1679438077407.png" alt="Tom_0-1679438077407.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2023 22:34:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-way-to-flag-if-there-is-a-missing-column-or-columns-in/m-p/865618#M341843</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-21T22:34:57Z</dc:date>
    </item>
    <item>
      <title>Re: Is there way to flag if there is a missing column or columns in between non-missing columns in S</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-way-to-flag-if-there-is-a-missing-column-or-columns-in/m-p/865703#M341866</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data expect;
  input (col1-col10) ($)  ;
cards;
A B B C . D A . A . 
B A . C A D A B . . 
A B B D D D . . . . 
A . B C B D A . . . 
A B B C . D A . . . 
. . C D E F . . . . 
A B . . E F . . . . 
;

data want ;
  set expect;
  length temp $ 200;
  array x{*} $ col: ;
  do i=1 to dim(x);
    temp=cats(temp,coalescec(x{i},'.'));
  end;
  flag=ifn(prxmatch('/[^\.]+\.+[^\.]+/',strip(temp)),1,0);
  drop temp i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Mar 2023 11:39:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-way-to-flag-if-there-is-a-missing-column-or-columns-in/m-p/865703#M341866</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-03-22T11:39:14Z</dc:date>
    </item>
  </channel>
</rss>

