<?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: Count successive missing values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Count-successive-missing-values/m-p/735412#M229095</link>
    <description>&lt;P&gt;Here you go&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id $2. var1 $2. var2 $2. var3 $2. var4 $2. var5 $2. var6 $2. var7 $2. var8 $2. var9 $2. var10 $2. var11 $2. var12 $2.;
cards;
A 1 2 3 . . . . . 1 1 1 3
B 3 3 2 1 3 2 1 . . . . .
C . . . . 1 2 3 1 2 3 2 .
D 3 . 1 . 3 . 1 . 3 . 1 .
F 1 3 . . 1 3 . . 1 3 . .
E 3 2 1 . . . . . 1 1 1 3
G 3 3 2 1 3 2 1 . . . . .
H . . . . . 1 2 3 1 2 3 2
I 3 . 1 . 3 . 1 . 3 . 1 .
J A E . . A E . . A E . . 
; 

data want(keep=id miss_lead miss_trail);
  set have;
  miss_lead=0;
  miss_trail=0;
  array v {*} var1-var12; 
  do i=1 to dim(v);
    if missing(v[i]) and miss_lead+1=i then miss_lead=i;
    if missing(v[dim(v)-i+1]) and miss_trail+1=i then miss_trail=i;
  end;
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-1618889162908.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/58354i853685DBC1ED9216/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1618889162908.png" alt="Patrick_0-1618889162908.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 20 Apr 2021 03:26:11 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2021-04-20T03:26:11Z</dc:date>
    <item>
      <title>Count successive missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-successive-missing-values/m-p/735187#M229028</link>
      <description>&lt;DIV&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have the following problem, I want to count the number of successive missing values in a row, only in specific lines, also I want to know when the missing values occur at the beginning or at the end of the sequence. Take as an example the following code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class="language-sas"&gt;data example;
  input id var1 var2 var3 var4 var5 var6 var7 var8 var9 var10 var11 var12;
cards;

A	1 2 3 . . . . . 1 1 1 3
B	3 3 2 1 3 2 1 . . . . .
C	. . . . 1 2 3 1 2 3 2 .
D	3 . 1 . 3 . 1 . 3 . 1 .
F	1 3 . . 1 3 . . 1 3 . .
E	3 2 1 . . . . . 1 1 1 3
G	3 3 2 1 3 2 1 . . . . .
H	. . . . . 1 2 3 1 2 3 2
I	3 . 1 . 3 . 1 . 3 . 1 .
J	A E . . A E . . A E . . 
; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In particular, I want to know the successive missing values in B,C,G and F.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 19 Apr 2021 09:11:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-successive-missing-values/m-p/735187#M229028</guid>
      <dc:creator>ramgouveia</dc:creator>
      <dc:date>2021-04-19T09:11:35Z</dc:date>
    </item>
    <item>
      <title>Re: Count successive missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-successive-missing-values/m-p/735245#M229037</link>
      <description>&lt;P&gt;Why B, C, G and F? Is that arbitrary?&lt;/P&gt;</description>
      <pubDate>Mon, 19 Apr 2021 13:44:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-successive-missing-values/m-p/735245#M229037</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-04-19T13:44:34Z</dc:date>
    </item>
    <item>
      <title>Re: Count successive missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-successive-missing-values/m-p/735251#M229040</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&lt;BR /&gt;&lt;BR /&gt;Because in those cases the missing values occur at the beginning or at the end of the sequence.</description>
      <pubDate>Mon, 19 Apr 2021 14:05:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-successive-missing-values/m-p/735251#M229040</guid>
      <dc:creator>ramgouveia</dc:creator>
      <dc:date>2021-04-19T14:05:17Z</dc:date>
    </item>
    <item>
      <title>Re: Count successive missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-successive-missing-values/m-p/735298#M229061</link>
      <description>&lt;P&gt;I edited your data set a bit since it doesn't quite work as stated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
  input id $2. var1 $2. var2 $2. var3 $2. var4 $2. var5 $2. var6 $2. var7 $2. var8 $2. var9 $2. var10 $2. var11 $2. var12 $2.;
cards;
A 1 2 3 . . . . . 1 1 1 3
B 3 3 2 1 3 2 1 . . . . .
C . . . . 1 2 3 1 2 3 2 .
D 3 . 1 . 3 . 1 . 3 . 1 .
F 1 3 . . 1 3 . . 1 3 . .
E 3 2 1 . . . . . 1 1 1 3
G 3 3 2 1 3 2 1 . . . . .
H . . . . . 1 2 3 1 2 3 2
I 3 . 1 . 3 . 1 . 3 . 1 .
J A E . . A E . . A E . . 
; 
run;

proc sort data=example; by id; run;
proc transpose data=example out=texample;
	var var1-var12;
	by id;
run;

data texample2;
	set texample;
	by id;
	if first.id then misscount=1*(col1='');
	else do;
		if col1='' then misscount+1;
		if col1 ne '' then misscount=0;
	end;
run;

proc tabulate data=texample2;
	class id;
	var misscount;
	tables id='', misscount*(max=''*f=6.0) / box='id';
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This provides the number of consecutively missing observations for each id.&lt;/P&gt;
&lt;PRE&gt;id misscount 
A  5 
B  5 
C  4 
D  1 
E  5 
F  2 
G  5 
H  5 
I  1 
J  2 

&lt;/PRE&gt;
&lt;P&gt;Is this close to what you want?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Apr 2021 15:50:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-successive-missing-values/m-p/735298#M229061</guid>
      <dc:creator>cminard</dc:creator>
      <dc:date>2021-04-19T15:50:29Z</dc:date>
    </item>
    <item>
      <title>Re: Count successive missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-successive-missing-values/m-p/735320#M229070</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/27112"&gt;@cminard&lt;/a&gt;&lt;BR /&gt;&lt;BR /&gt;The result I want is:&lt;BR /&gt;&lt;BR /&gt;id misscount&lt;BR /&gt;A 0&lt;BR /&gt;B 0&lt;BR /&gt;C 4&lt;BR /&gt;D 0&lt;BR /&gt;E 0&lt;BR /&gt;F 0&lt;BR /&gt;G 5&lt;BR /&gt;H 5&lt;BR /&gt;I 0&lt;BR /&gt;J 0&lt;BR /&gt;&lt;BR /&gt;I want to count the initial missing values&lt;BR /&gt;&lt;BR /&gt;and&lt;BR /&gt;&lt;BR /&gt;id misscount&lt;BR /&gt;A 0&lt;BR /&gt;B 5&lt;BR /&gt;C 1&lt;BR /&gt;D 1&lt;BR /&gt;E 2&lt;BR /&gt;F 0&lt;BR /&gt;G 5&lt;BR /&gt;H 0&lt;BR /&gt;I 1&lt;BR /&gt;J 2&lt;BR /&gt;&lt;BR /&gt;I want to count the last missing values.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Apr 2021 17:22:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-successive-missing-values/m-p/735320#M229070</guid>
      <dc:creator>ramgouveia</dc:creator>
      <dc:date>2021-04-19T17:22:33Z</dc:date>
    </item>
    <item>
      <title>Re: Count successive missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-successive-missing-values/m-p/735321#M229071</link>
      <description>&lt;P&gt;Why is misscount = 1 for ID = "H"?&lt;/P&gt;</description>
      <pubDate>Mon, 19 Apr 2021 17:18:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-successive-missing-values/m-p/735321#M229071</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-04-19T17:18:44Z</dc:date>
    </item>
    <item>
      <title>Re: Count successive missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-successive-missing-values/m-p/735322#M229072</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&lt;BR /&gt;&lt;BR /&gt;Is 0. Sorry for the error.</description>
      <pubDate>Mon, 19 Apr 2021 17:22:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-successive-missing-values/m-p/735322#M229072</guid>
      <dc:creator>ramgouveia</dc:creator>
      <dc:date>2021-04-19T17:22:01Z</dc:date>
    </item>
    <item>
      <title>Re: Count successive missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-successive-missing-values/m-p/735333#M229078</link>
      <description>&lt;P&gt;Ok. The whole thing can be done like this then.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(keep = id misscount);
   set example;
   array v var12 - var1;
   misscount = 0;
   do over v;
      if not missing(v) then leave;
      misscount + 1;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;id  misscount 
A   0 
B   5 
C   1 
D   1 
F   2 
E   0 
G   5 
H   0 
I   1 
J   2 
&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Apr 2021 17:56:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-successive-missing-values/m-p/735333#M229078</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-04-19T17:56:02Z</dc:date>
    </item>
    <item>
      <title>Re: Count successive missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-successive-missing-values/m-p/735412#M229095</link>
      <description>&lt;P&gt;Here you go&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id $2. var1 $2. var2 $2. var3 $2. var4 $2. var5 $2. var6 $2. var7 $2. var8 $2. var9 $2. var10 $2. var11 $2. var12 $2.;
cards;
A 1 2 3 . . . . . 1 1 1 3
B 3 3 2 1 3 2 1 . . . . .
C . . . . 1 2 3 1 2 3 2 .
D 3 . 1 . 3 . 1 . 3 . 1 .
F 1 3 . . 1 3 . . 1 3 . .
E 3 2 1 . . . . . 1 1 1 3
G 3 3 2 1 3 2 1 . . . . .
H . . . . . 1 2 3 1 2 3 2
I 3 . 1 . 3 . 1 . 3 . 1 .
J A E . . A E . . A E . . 
; 

data want(keep=id miss_lead miss_trail);
  set have;
  miss_lead=0;
  miss_trail=0;
  array v {*} var1-var12; 
  do i=1 to dim(v);
    if missing(v[i]) and miss_lead+1=i then miss_lead=i;
    if missing(v[dim(v)-i+1]) and miss_trail+1=i then miss_trail=i;
  end;
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-1618889162908.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/58354i853685DBC1ED9216/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1618889162908.png" alt="Patrick_0-1618889162908.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 03:26:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-successive-missing-values/m-p/735412#M229095</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-04-20T03:26:11Z</dc:date>
    </item>
    <item>
      <title>Re: Count successive missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-successive-missing-values/m-p/735529#M229139</link>
      <description>Thank you very much &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&lt;BR /&gt;&lt;BR /&gt;It worked.</description>
      <pubDate>Tue, 20 Apr 2021 12:56:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-successive-missing-values/m-p/735529#M229139</guid>
      <dc:creator>ramgouveia</dc:creator>
      <dc:date>2021-04-20T12:56:54Z</dc:date>
    </item>
  </channel>
</rss>

