<?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: How to find the rows for which consecutive columns have blank values? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-rows-for-which-consecutive-columns-have-blank/m-p/776078#M246749</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/361528"&gt;@Shradha1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is good practise to supply example input data not as a table, but as&amp;nbsp;a data step that can be run to&amp;nbsp;create a sas data set, so anybody answering your post has something to work on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think in this case the best way is to use an array to hold all months 1-12 for a given costomer and then traverse the array and count consecutive missing months. If there are at least 6 consecutive missing months, then store the the month number where the costomer reappears, if this happens.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* Create test data ;
data have;
input Customer$ M1-M12;
cards;
A	.	94	63	106	424	252	499	356	435	469	200	423
B	.	.	.	.	.	.	.	13	137	440	75	99
C	67	118	364	.	.	.	.	.	.	156	40	415
D	430	423	.	.	.	.	54	165	26	477	129	411
;
run;

* Analyze;
data want (keep=Customer ReAppear); 
	set have;

	* Declare array containing 12 months and initiate counters;
	array spend M1-M12;
	Zerospend = 0;
	ReAppear = 0;

	* Loop over array, count consecutive missings and set reapprearing month;
	do i = 1 to 12;
		if missing(Spend{i}) then Zerospend = Zerospend + 1;
		else do;
			if Zerospend &amp;gt;= 6 then ReAppear = i;
			Zerospend = 0;
		end;
	end;

	* Output only if conditions are met;
	if ReAppear &amp;gt; 0 then output;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The result is B 8 and C 10.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 24 Oct 2021 11:03:19 GMT</pubDate>
    <dc:creator>ErikLund_Jensen</dc:creator>
    <dc:date>2021-10-24T11:03:19Z</dc:date>
    <item>
      <title>How to find the rows for which consecutive columns have blank values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-rows-for-which-consecutive-columns-have-blank/m-p/776068#M246740</link>
      <description>&lt;P&gt;I have a list of customers, and against each customer I have their monthly Spend for 13 consecutive months from M1 to M12.&lt;/P&gt;
&lt;P&gt;Now, I want to select only those customers who have had zero spends for at least 6 or more consecutive months(inactive customers), and also the month from when their spend started reappearing post inactivity.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My dataset looks like this:&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 624pt;" border="0" width="832" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" style="height: 15.0pt; width: 48pt;"&gt;Customer&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;M1&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;M2&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;M3&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;M4&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;M5&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;M6&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;M7&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;M8&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;M9&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;M10&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;M11&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;M12&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;A&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD align="right"&gt;94&lt;/TD&gt;
&lt;TD align="right"&gt;63&lt;/TD&gt;
&lt;TD align="right"&gt;106&lt;/TD&gt;
&lt;TD align="right"&gt;424&lt;/TD&gt;
&lt;TD align="right"&gt;252&lt;/TD&gt;
&lt;TD align="right"&gt;499&lt;/TD&gt;
&lt;TD align="right"&gt;356&lt;/TD&gt;
&lt;TD align="right"&gt;435&lt;/TD&gt;
&lt;TD align="right"&gt;469&lt;/TD&gt;
&lt;TD align="right"&gt;200&lt;/TD&gt;
&lt;TD align="right"&gt;423&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;B&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD align="right"&gt;13&lt;/TD&gt;
&lt;TD align="right"&gt;137&lt;/TD&gt;
&lt;TD align="right"&gt;440&lt;/TD&gt;
&lt;TD align="right"&gt;75&lt;/TD&gt;
&lt;TD align="right"&gt;99&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;C&lt;/TD&gt;
&lt;TD align="right"&gt;67&lt;/TD&gt;
&lt;TD align="right"&gt;118&lt;/TD&gt;
&lt;TD align="right"&gt;364&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD align="right"&gt;156&lt;/TD&gt;
&lt;TD align="right"&gt;40&lt;/TD&gt;
&lt;TD align="right"&gt;415&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;D&lt;/TD&gt;
&lt;TD align="right"&gt;430&lt;/TD&gt;
&lt;TD align="right"&gt;423&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD align="right"&gt;54&lt;/TD&gt;
&lt;TD align="right"&gt;165&lt;/TD&gt;
&lt;TD align="right"&gt;26&lt;/TD&gt;
&lt;TD align="right"&gt;477&lt;/TD&gt;
&lt;TD align="right"&gt;129&lt;/TD&gt;
&lt;TD align="right"&gt;411&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, from this dataset, I would select Customer B and C, as they have null spends for 6 or more consecutive months and for customer B, the month when spend restarted would be M8, and it will be M10 for Customer C.&lt;/P&gt;
&lt;P&gt;So, my resultant dataset will look like this:&lt;/P&gt;
&lt;TABLE width="128"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;Customer&lt;/TD&gt;
&lt;TD width="64"&gt;Month&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;B&lt;/TD&gt;
&lt;TD&gt;M8&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;C&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;M10&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do I achieve this? Any help would be much appreciated.&lt;/P&gt;
&lt;P&gt;Thanks a lot!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Oct 2021 08:11:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-rows-for-which-consecutive-columns-have-blank/m-p/776068#M246740</guid>
      <dc:creator>Shradha1</dc:creator>
      <dc:date>2021-10-24T08:11:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the rows for which consecutive columns have blank values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-rows-for-which-consecutive-columns-have-blank/m-p/776076#M246747</link>
      <description>&lt;PRE&gt;data have;
infile cards expandtabs truncover;
input Customer	$ M1	M2	M3	M4	M5	M6	M7	M8	M9	M10	M11	M12;
cards;
A	.	94	63	106	424	252	499	356	435	469	200	423
B	.	.	.	.	.	.	.	13	137	440	75	99
C	67	118	364	.	.	.	.	.	.	156	40	415
D	430	423	.	.	.	.	54	165	26	477	129	411
;

data want;
set have;
array x{*} M: ;
count=0;
do i=1 to dim(x);
 if missing(x{i}) then count+1;
  else do;
         count=0;
		 if _count&amp;gt;5 then month=vname(x{i});
	   end;
  _count=count;
end;
drop count _count i;
run;&lt;/PRE&gt;</description>
      <pubDate>Sun, 24 Oct 2021 10:48:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-rows-for-which-consecutive-columns-have-blank/m-p/776076#M246747</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-10-24T10:48:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the rows for which consecutive columns have blank values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-rows-for-which-consecutive-columns-have-blank/m-p/776078#M246749</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/361528"&gt;@Shradha1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is good practise to supply example input data not as a table, but as&amp;nbsp;a data step that can be run to&amp;nbsp;create a sas data set, so anybody answering your post has something to work on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think in this case the best way is to use an array to hold all months 1-12 for a given costomer and then traverse the array and count consecutive missing months. If there are at least 6 consecutive missing months, then store the the month number where the costomer reappears, if this happens.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* Create test data ;
data have;
input Customer$ M1-M12;
cards;
A	.	94	63	106	424	252	499	356	435	469	200	423
B	.	.	.	.	.	.	.	13	137	440	75	99
C	67	118	364	.	.	.	.	.	.	156	40	415
D	430	423	.	.	.	.	54	165	26	477	129	411
;
run;

* Analyze;
data want (keep=Customer ReAppear); 
	set have;

	* Declare array containing 12 months and initiate counters;
	array spend M1-M12;
	Zerospend = 0;
	ReAppear = 0;

	* Loop over array, count consecutive missings and set reapprearing month;
	do i = 1 to 12;
		if missing(Spend{i}) then Zerospend = Zerospend + 1;
		else do;
			if Zerospend &amp;gt;= 6 then ReAppear = i;
			Zerospend = 0;
		end;
	end;

	* Output only if conditions are met;
	if ReAppear &amp;gt; 0 then output;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The result is B 8 and C 10.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Oct 2021 11:03:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-rows-for-which-consecutive-columns-have-blank/m-p/776078#M246749</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2021-10-24T11:03:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the rows for which consecutive columns have blank values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-rows-for-which-consecutive-columns-have-blank/m-p/776127#M246772</link>
      <description>Thank you for the response! This helped a lot</description>
      <pubDate>Mon, 25 Oct 2021 04:34:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-rows-for-which-consecutive-columns-have-blank/m-p/776127#M246772</guid>
      <dc:creator>Shradha1</dc:creator>
      <dc:date>2021-10-25T04:34:28Z</dc:date>
    </item>
  </channel>
</rss>

